Trying to start an Eclise Maven Web-Project in J2EE preview server (in Glassfish4, it works fine) i get an error:
java.lang.ClassNotFoundException: javax.faces.webapp.FacesServlet
Howewer, trying to make the fix like adviced on some another topik in this forum:
set in properties->project->fasets-> user library the jsf-api-2.1,jar
(as external jar, what is not nice),
i get another error :
Started ServerConnector#1727e0ec{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/faces/webapp/FacesServlet
Searching for solution i found the info, that this is caused by classes in
javaee-web-api what are just blueprints and server must have implementaion for them.
That is why for example you write maven dependency for that as provided, like:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
So i guess it is in this external jar too, it just not suppose to be included. What jar must i add then to fix this problem, or there is another better solution for this?
you can add below dependency into project pom.xml
and try to update the project.'
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1.7</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.1.7</version>
</dependency>
or you can also add
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
Related
I wrote a console application which reads a text file to String and then processes the file contents. I used maven in my project, enabled autoimport, added proper dependencies but still, when I try to process the String by using replace() method (this method belongs to org.apache.commons.lang3.StringUtils class) I get the undermentioned error. Moreover, when I launch my application in intelliJ, it works perfectly and everything seems to be fine. When I compile and build .jar file with maven and then launch it via terminal it reports this error:
Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/commons/lang3/StringUtils at
com.company.Reader.process(Reader.java:47) at
com.company.App.main(App.java:9) Caused by:
java.lang.ClassNotFoundException: org.apache.commons.lang3.StringUtils
at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at
java.lang.ClassLoader.loadClass(ClassLoader.java:424) at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) at
java.lang.ClassLoader.loadClass(ClassLoader.java:357)
Also, the dependencies in my pom.xml look like this:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.8.4</version>
<scope>test</scope>
</dependency>
</dependencies>
I have no idea what might be wrong. I know a way to make my program work, that is, to download .jar with commons-lang3 manually and include it in my project, but this is not a satisfying solution for me. Does anyone know why do I get such error?
Thanks in advance
You didn't put your entire pom.xml, but I guess that you forgot the dependency:
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
You said that your project works inside Intellij, then you already have the common-lang3 in your computer.
I think the problem resides in the maven dependencies.
Try to execute: mvn clean install via command line in the root folder of your project.
You need to put your commons-lang3-3.4.jar in the classpath
Two links to help you:
https://docs.oracle.com/javase/7/docs/technotes/tools/windows/classpath.html
Run a JAR file from the command line and specify classpath
I'm getting the following error:
com.sun.xml.messaging.saaj.soap.MessageFactoryImpl cannot be cast to javax.xml.soap.MessageFactory
Is there a way to force use of the MessageFactory from saaj-api over the one from javaee-api? At least that's what I think may need to be done.
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.3.15</version>
</dependency>
<dependency>
<groupId>javax.xml.soap</groupId>
<artifactId>saaj-api</artifactId>
<version>1.3.5</version>
</dependency>
<prefer-application-packages>
<package-name>javax.xml.soap.*</package-name>
<package-name>javax.xml.ws.*</package-name>
<package-name>com.sun.xml.messsaging.saaj.*</package-name>
</prefer-application-packages>
Generally speaking you don't want to package API's in your war/ear files as they should be provided by the application server. I would set the scope to provided on those two api dependencies and work from there.
Ive been using anotation for my beans (I havent used them before) and I found out I have to include some dependencies and so on, like this:
<!--JSF API-->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.0.2</version>
</dependency>
<!-- PrimeFaces -->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>3.3</version>
</dependency>
<!-- JSF -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<!-- Javax Servlet. This needs to be included for runtime only! -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
and well.. the problem is that the I keep getting the error of
The import javax.faces cannot be resolved
Every time I need to use the managed bean... I am using Maven and I am supposed to have downloaded all things I need, I also tried other POM and in that project I can use anotations, so, I guess is a misconfiguratino of the POM? I didnt do anything special to ecplise, except enable the maven clean, maven eclipse, and maven eclipse skip test
I really checked other answers, like these:
The import javax.servlet can't be resolved
How do I import the javax.servlet API in my Eclipse project?
but nothing, any idea what could be wrong??
You should not import the servlet API but implementation of the API, for example the servlet container implementation you want on which you want to run your project : Tomcat, JBoss, Websphere, Glassfish....
E.g. for tomcat :
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<version>7.0.30</version>
<scope>provided</scope>
</dependency>
Thanks for the answer, I checked that using Maven its a little bit different and in the built path you have to specify the path for your maven repository, so, it will incluide all libraries directly or you can copy and past them into your project
My Java app requires org.objectweb.asm library. I specified 'asm' dependency in pom. That deploys the library together with the app. Still the app throws exception NoClassDefFoundError: org/objectweb/asm/ClassVisitor.
java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor
at com.sun.jersey.api.core.PackagesResourceConfig.init(PackagesResourceConfig.java:112)
at com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:78)
... many more
How can I fix the problem?
Details:
I am using Glassfish 2.1.1. The app requires jersey 1.1.4, jersey requires asm 3.1. I assume 1.1.4 version is required by glassfish 2.1.1
If I run Glassfish updatetool and install Jersey on the server then my app loads and runs with no problems. My client doesn't have Jersey installed on their server and they can not use updatetool.
Glassfish 2.1.1 updatetool installs jersey 1.1.4 and asm-3.1.jar in glassfish/lib directory.
When jersey is uninstalled, updatetool removes asm too.
If I include jersey and asm as dependencies and deploy my war file then jersey and asm jars go into local location, e.g. glassfish/domains/domain1/applications/j2ee-modules/MYAPPNAME/WEB-INF/lib/asm-3.1.jar.
Glassfish updatetool puts asm into lib folder: glassfish/lib directory the app start deploying and working correctly.
Here is my maven pom file dependency section:
<dependencies>
<dependency>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-bundle</artifactId>
<version>1.1.4</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.jersey-test-framework</groupId>
<artifactId>jersey-test-framework-grizzly2</artifactId>
<version>1.17.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>1.0.0.Final</version>
<scope>provided</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
I had a conflict with an older jersey library stored in glassfish/lib folder:
glassfish/lib/jersey-bundle-1.0.3.1.jar
It was loaded and used instead of jars placed in a folder local to the app:
glassfish/domains/domain1/applications/j2ee-modules/MYAPPNAME/WEB-INF/lib/
Jersey jar from 'lib' folder was looking for 'asm' library in the same 'lib' folder, hence my locally placed asm-3.1.jar was never found.
I expected that 'local' jars were loaded first. Appeared that the search order is different. Is that really the case? Please tell me if I am wrong.
I found the problem by verifying which library is used with the following code:
logger.debug(PackagesResourceConfig.class.getResource("PackagesResourceConfig.class"));
Note PackagesResourceConfig class listed in the exception thrown.
Hopefully this answer will help someone else to save their time.
Try something like that in your pom:
<dependency>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>3.3.1</version>
</dependency>
I'm trying to use embedded ActiveMQ broker for unit testing, as explained here: http://activemq.apache.org/how-to-unit-test-jms-code.html
What Maven dependencies I need to include? At the moment I have just these:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-core</artifactId>
<version>5.5.0</version>
</dependency>
This is what I'm getting:
java.lang.ClassFormatError: Absent Code attribute in method that
is not native or abstract in class file javax/jms/JMSException
When trying to instantiate a broker:
final BrokerService broker = new BrokerService();
What else should I add to the list of Maven dependencies? (I'm not using Spring)
The solution is simple, just need to remove the javax:javaee-api dependency.
can you try activemq-all:
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-all</artifactId>
<version>5.5.0</version>
</dependency>
moved the javaee dependency to the end of the class path. This solved my problem.