I have a multi-module project in Eclipse, which works fine.
Now I want to work with IntelliJ (I have 12.1), so I imported project to IntelliJ, and have configured below things in it:
All modules
configured all lib (.jar) files with each project where I need (by adding lib)
have configured module dependencies
have configured tomcat7 with them, and added it in dependency of module too
Everything looks OK, but when I run the project it shows:
Caused by: java.lang.NoClassDefFoundError: org/xx/yyy/zzzz
Although org.xx.yyy.zzzz class exist in model module, which is already added to web module (my project has 2 modules web and model), and also scope of dependency is set to provided.
What should I try to resolve this problem? Help me if I am missing something.
Finally I got the answer.
I kept the scope to provided, and Added model module to artifacts and it worked. :)
Related
I am getting ClassNotFoundException and NoClassDefFoundError exceptions when I attempt to run my application using a maven defined dependency.
I added my maven dependency for the jar in question to my pom.xml file with the following declaration:
<dependency>
<groupId>spy</groupId>
<artifactId>spymemcached</artifactId>
<version>2.8.4</version>
<scope>provided</scope>
</dependency>
This added the relevant JAR file to my Maven Dependencies folder in Eclipse. I can access the classes in code but I get the mentioned exceptions once I run the application.
The jar is referenced in my Java build path under Maven dependencies:
My local maven repository is added to my classpath:
When I attempt to run the application, I get the following two exceptions:
java.lang.NoClassDefFoundError: Lnet/spy/memcached/MemcachedClient;
java.lang.ClassNotFoundException: net.spy.memcached.MemcachedClient
Can anyone point me in the right direction?
Change provided to compile
Provided
This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.
<scope>provided</scope>
"Provided" scope implies that the dependencies should be available only during compile phase and they will be available elsewhere during runtime and Maven shouldn't package them with the rest of the jars and classes of the current application.
Your dependency doesn't seem to be of "provided" scope. Remove that scope from your dependency definition and the jars will be present in your packaged jar/war/ear.
I was facing the same issue but i didn't have the tag defined on my POM, it was always working fine until one day all of a sudden started giving me that error in my local machine for no reason, the dependency was correctly set up in the POM and the jar was present in the local maven repository.
I tried cleaning the project and updating maven project but nothing, none of the other solutions suggested on other posts worked for me either.
I was finally able to solve it by going to the servers tab -> right click on Tomcat v8.0 -> browse deployment location
this should lead you to a temp folder like
.metadata.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps
then you browse to your project folder -> WEB-INF -> lib -> here i found out that the jar from the library that was giving the error was missing, so i just copied it from .m2\repository
Restarted the server and it started working as usual again.
I hope this helps some body facing the same issue.
Answer somewhat related to your problem, but still can help others.
Adding <scope>compile</scope> to the dependency was not enough in my case. I also had to add <packaging>jar</packaging> to the target module's pom.
I was also facing the same problem, after trying various solutions the issue was resolved by following steps...
click on server >open launch configurations >Arguments (copy
"LocalPath\temp0\wtpwebapps" path).
go to "LocalPath\temp0\wtpwebapps\ProjectName\WEB-INF\lib".
copy the JAR (which was causing ClassNotFoundException) from .m2 and place it in "LocalPath\temp0\wtpwebapps\ProjectName\WEB-INF\lib" path.
I have a Maven project, imported from Eclipse, where the dependencies are set to scope provided. When the project is deployed, the jars are deployed as well so that works fine.
While developing, however, I use a "debugging project" that calls the Maven project, and when it runs I get a bunch of Class Not Found errors when the Maven dependencies are set to provided.
If I change the scope of the Maven dependencies to Compile then the project works fine.
If I change the scope of the dependencies to compile, would that change the output of the project? i.e. add a bunch of jars? That would be undesirable.
I also tried to change the Debug Configuration settings and specified the Maven project in "Use classpath of module", but then the files of the debugging project are not found.
How can I specify the classpath to be of both the Maven project and the debugging project, so that classes from both projects including the dependencies will be on the classpath?
Thanks!
There are 3 types of dependency scope: compile, test, and provided,
compile: the dependency library will be used in all steps: compile , test and run,
test: the dependency library will only be used in the test
provided: the dependency library will only be used in compile and test, but in the run time, the dependency library must be provided by the container otherwise it will throw class no find issues.
Your issues is that you did not provide the dependency library in the run environment ( container) when running your project.
hope this can help you
How did you import the project to Idea? If the project is opened as a Maven projects, it should work out of box.
Can you try to open the project by selecting pom.xml?
I have multi module maven project, that is build with gwt as a main web framework. Here is github repo.
Everythink works as it should as I supose. I haven't got anything wrong.
Unfortunatelly the problems occur when I try to import this project into eclipse (as maven project). I can not compile this project (using RMB on project in Package Explorer -> Google -> GWT Compile).
I am getting an error:
Loading inherited module 'src.main.resources.pl.derp.parent'
Loading inherited module 'pl.derp.shared'
[ERROR] Unable to find 'pl/derp/shared.gwt.xml' on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?
When I tried to RMB on Project name in Package Explorer -> Run -> Run as Web application (GWT Super Dev Mode)
I've got:
Working directory does not exist: /home/danielo/eclipseGwt/gwt_2.7.0_maven_eclipse/web/src/main/webapp
I've added modules to build path.
I've followed this instruction
I think, that I've done everything to make it work, but still can make it work.
I think the problem is in packages name, and the way they are treated by maven and eclipse. They are treated in diferent ways.
Maven easily find every class (f.e.: package pl.derp.web;) needed and compile. The eclipse is trying to find them by f.e.: src.main.java.pl.derp.web but can't found it.
Really I don't know how to resolve this issue?
I am not sure witch package name patter is better (src.main.java.pl.derp.server or pl.derp.server)- for me the shorter is better.
To run this project in maven (it is well described here):
mvn clean install
mvn tomcat7:run-war-only
and in second shell:
mvn gwt:run -pl web
And in Eclipse I think I am running built in Jetty server
Please give me some help.
You apparently have a single Eclipse project, with server, shared, and web declared as source directories. When using M2Eclipse, you should have 3 projects, each with their src/{main,test}/{java,resources} declared as source directories. At a minimum, without M2Eclipse, the source directories must be the src/{main,test}/{java,resources}, whether you have 1 or 3 projects.
This is why Eclipse looks for src.main.java.pl.derp.server instead of pl.derp.server, and why GWT fails too (classpath is similarly wrong).
I have a problem when I try to run my project
The exception is :
java.lang.ClassNotFoundException: org.jfree.chart.plot.PlotOrientation
I have added these libs to my project and to my classpath
commons-beanutils-1.8.0
commons-collections-2.1.1
commons-digester-1.7
commons-javaflow-20060411
commons-logging-1.0.4
groovy-all-1.8.6
iText-2.1.7
jasperreports-5.2.0
jcommon-1.0.17
jfreechart-1.0.13
I follow some solution to this website but I still have the Exception...
I have this problem since 2 days and I never get solutions and now I really need help.
Thanks!!!
If you're using a dependency manager (Maven, SBT, Ivy, Gradle, etc.) copy and paste the respective snippet above into your project file. If you're using a dependency manager, that's all there is to resolving this exception.
https://repo1.maven.org/maven2/info/novatec/testit/livingdoc-confluence5-plugin/1.1.2/livingdoc-confluence5-plugin-1.1.2.jar
All of the following jars/dependencies, contain a class with the same name as your missing class. Add the correct jar/dependency (preferably the one relevant to your project), to the classpath of your project, and you should no longer receive the error.
You can download the JAR directly, or configure a build tool to do your dependency management for you. (e.g. ivy+ant, gradle, maven, etc)
Additionally, this link provides instructions on manually adding a JAR to your classpath.
Ask if you need more help with this.
I am getting ClassNotFoundException and NoClassDefFoundError exceptions when I attempt to run my application using a maven defined dependency.
I added my maven dependency for the jar in question to my pom.xml file with the following declaration:
<dependency>
<groupId>spy</groupId>
<artifactId>spymemcached</artifactId>
<version>2.8.4</version>
<scope>provided</scope>
</dependency>
This added the relevant JAR file to my Maven Dependencies folder in Eclipse. I can access the classes in code but I get the mentioned exceptions once I run the application.
The jar is referenced in my Java build path under Maven dependencies:
My local maven repository is added to my classpath:
When I attempt to run the application, I get the following two exceptions:
java.lang.NoClassDefFoundError: Lnet/spy/memcached/MemcachedClient;
java.lang.ClassNotFoundException: net.spy.memcached.MemcachedClient
Can anyone point me in the right direction?
Change provided to compile
Provided
This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.
<scope>provided</scope>
"Provided" scope implies that the dependencies should be available only during compile phase and they will be available elsewhere during runtime and Maven shouldn't package them with the rest of the jars and classes of the current application.
Your dependency doesn't seem to be of "provided" scope. Remove that scope from your dependency definition and the jars will be present in your packaged jar/war/ear.
I was facing the same issue but i didn't have the tag defined on my POM, it was always working fine until one day all of a sudden started giving me that error in my local machine for no reason, the dependency was correctly set up in the POM and the jar was present in the local maven repository.
I tried cleaning the project and updating maven project but nothing, none of the other solutions suggested on other posts worked for me either.
I was finally able to solve it by going to the servers tab -> right click on Tomcat v8.0 -> browse deployment location
this should lead you to a temp folder like
.metadata.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps
then you browse to your project folder -> WEB-INF -> lib -> here i found out that the jar from the library that was giving the error was missing, so i just copied it from .m2\repository
Restarted the server and it started working as usual again.
I hope this helps some body facing the same issue.
Answer somewhat related to your problem, but still can help others.
Adding <scope>compile</scope> to the dependency was not enough in my case. I also had to add <packaging>jar</packaging> to the target module's pom.
I was also facing the same problem, after trying various solutions the issue was resolved by following steps...
click on server >open launch configurations >Arguments (copy
"LocalPath\temp0\wtpwebapps" path).
go to "LocalPath\temp0\wtpwebapps\ProjectName\WEB-INF\lib".
copy the JAR (which was causing ClassNotFoundException) from .m2 and place it in "LocalPath\temp0\wtpwebapps\ProjectName\WEB-INF\lib" path.