primefaces-extensions / primefaces-extensions.github.com

Organization repo, only for homepage, wiki and issue tracker
https://primefaces-extensions.github.io/
70 stars 22 forks source link

InputPhone causes NoClassDefFoundError on deployment due to missing com.googlecode.libphonenumber #765

Closed Theocom closed 4 years ago

Theocom commented 4 years ago

Glassfish 5.1 log: Source Document: jar:file:/home/..path to../domains/domain1/applications/MyApp/WEB-INF/lib/primefaces-extensions-8.0.jar!/META-INF/faces-config.xml Cause: Class 'org.primefaces.extensions.component.inputphone.InputPhoneRenderer' is missing a runtime dependency: java.lang.NoClassDefFoundError: com/google/i18n/phonenumbers/NumberParseException

I'm not using inputphone at all

melloware commented 4 years ago

InputPhone dependency is class loaded by the InputPhoneRenderer so you will probably need to add the JAR to your app to make it classload.

        <!-- InputPhone dependencies -->
        <dependency>
            <groupId>com.googlecode.libphonenumber</groupId>
            <artifactId>libphonenumber</artifactId>
           <version>8.10.17</version>
        </dependency>

@jepsar We should probably look at some kind of class loading detection like Primefaces does if certain libs don't exist etc.

Theocom commented 4 years ago

Hi melloware, thanks for the fast reply Is it possible to remove the input phone element instead? I have a working app on version 7.0 and wanted to check if the 8.0 works without refactoring. I'm only using the fluidgrid, which is created dynamically inside primefaces tabview tabs. After switching to ver 8.0 the whole tabview became unresponsible and i switched back to ver 7.0

jepsar commented 4 years ago

The dependency should be added automatically if you are using Maven (it's not scope provided).

@melloware do you know which component uses the class loading detection you mentioned? I'd like to have a look at it.

Edit: do you mean LangUtils.tryToLoadClassForName?

melloware commented 4 years ago

Look at this class. https://github.com/primefaces/primefaces/blob/master/src/main/java/org/primefaces/context/PrimeApplicationContext.java

it uses things to detect if Tika is on the classpath before loading etc. and Yes those LangUtils are used.

melloware commented 4 years ago

@Theocom Just add LibPhoneNumber to your WAR or classpath if you want to test 8.0 out. You can always remove it later when we fix this issue.

jepsar commented 4 years ago

@melloware Looking at https://github.com/primefaces/primefaces/blob/b44a915249d3c9f42014c2b27d8944f1222cb275/src/main/java/org/primefaces/component/texteditor/TextEditorRenderer.java#L63 it seems to me that the tag (renderer) will work as long as all directly imported classes are present. So if we would move the phone number validation to a different class (as done in https://github.com/primefaces/primefaces/blob/master/src/main/java/org/primefaces/util/HtmlSanitizer.java ) it will work? Am I right?

melloware commented 4 years ago

I think you are right. I can give it a shot on Monday if you don’t have time.

jepsar commented 4 years ago

I can have a look. First I'd like to try to reproduce the problem.

melloware commented 4 years ago

Good idea should be able to make the dependency <optional>true</optional> in the master-pom. Rebuild then run the Showcase.

jepsar commented 4 years ago

I was able to test in a small app with the dependency set to

    <dependency>
      <groupId>org.primefaces.extensions</groupId>
      <artifactId>primefaces-extensions</artifactId>
      <version>8.0.1-SNAPSHOT</version>
      <exclusions>
        <exclusion>
          <groupId>com.googlecode.libphonenumber</groupId>
          <artifactId>libphonenumber</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
jepsar commented 4 years ago

@Theocom you could build 8.0.1-SNAPSHOT and use that. See https://github.com/primefaces-extensions/primefaces-extensions.github.com/wiki/Getting-Started#build-from-source (skip the showcase part)