I had a perfectly running Eclipse project with Maven and project dependencies. Now I want to switch to IntelliJ IDEA - the import of my projects worked nicely (now called module with Maven and module dependencies), all the Maven configuration seemed to work out of the box (can expand libs and see source code).
When I run my module I get:
Exception in thread "main" java.lang.NoClassDefFoundError: com/thoughtworks/xstream/XStream
From a dependent module, xstream-1.4.2.jar is correctly in the build path of that module.
What I tried and did not work:
Importing projects as Eclipse projects, applying Maven nature/framework support afterwards
Importing projects as Maven projects
Invalidate caches
Maven Reimport & Generate Sources and Update Folders
What worked but is not a solution: I can add the xstream-1.4.2.jar to the dependencies of the module I am running, but then it fails with the next missing jar. So it seems as if it does not find the jars referenced in referenced modules.
Often one encounters the NoClassDefFoundError when there are two libs in different versions on the classpath - I double checked, there is only one xstream*.jar file there.
I appreciate any help.
Thank you, Marcel
Is xstream-1.4.2.jar located in the correct groupid/artificatid/1.4.2/ folder under .m2 repository?
If you are running on linux, .m2 will be located under /home//.m2
If you are running on Windows, .m2 folder will be located under C:\Users\.m2
Related
So I have the following project structure Sporium is a working set with the maven multimodule spigot-parent my problem now is when I define this pom.xml in my project it will not use the created dependency in the .m2 folder but instead it will use the files in the maven module project of my IDE's workspace which doesn't work because they are raw, unpatched and uncompiled files
as seen here. Any idea how I can tell maven to not use the version in my workspace and only search in the local repo .m2 folder?
Right click on the project, choose "Maven" and then disable Workspace resolution.
Then the projects are not resolved from your workspace any more.
I just checked out some projects from svn to my pc, and I tried to import the projects into my workspace.
But I failed to import some of them, and eclipse didn't recognize those projects(didn't show up in the import window).
And then I turn to google and found a solution -"add .projects and .classpath file to project folder" works.
However, what make me really confusing is that I foundthe projects I successfully imported into workspace without manually adding the files for them also don't contain .projects and .classpath. Eclipse just create the files for them automatically after import, so it seems that the fail of importing projects(or recognizing projects during import) is not just simply because of the lack of .projects and .classpath.
Does anyone know what cause the difference?
How does eclipse exactly recognize a project as importable project?
*eclipse version info here
Eclipse or any other IDE doesn't required .classpath or .project files. These files will be auto created during the project import. IDE can capable to pull the artifacts from maven central repo automatically by using build descriptor file such as pom.xml or build.graddle.
The files .classpath and .project will store the paths from local machine, if we carry them to another system, the artificats and other dependencies may not be present in the same directory, so it will start complaining build errors. Thats why while committing to GIT always there is .gitignore, so that local configuration will not carry to others while contributing.
I have two maven projects in eclipse, a jar and a war. The war has a dependency on the jar, which is resolved through workspace resolution.
The problem is that the jar has generated classes, which are added to the jar through build-helper-maven-plugin. But these classes aren't being properly resolved in the war project. For example: It auto-completes the class but keeps saying it can't be found. More importantly, when running glassfish through eclipse, I get a class not found for these classes.
If I disable workspace resolution everything works fine, but I hope to use workspace resolution. Any ideas?
EDIT:
Folder structure. The maven workspace resolved persistence project in the lower image is in the Maven Dependencies folder, essentially your seeing the top and bottom of the folder.
IDK if I am correct, but you are talking about Eclipse problems - it does not "see" generated classes right?
To fix it, you have to add generated sources directory to the eclipse's build path and it should fix your problem.
Right click on project that has generated classes->buildPath->conf
buildpath
In source tab - click add folder
Select the directory where build helper generates java files.
Generated classes will apear as additional source folder in Eclipse's project hierarchy and voila, Eclipse can autocomplete and resolve generated classes now on the same conditionstha any it would on any other class written by you in the same project by hand.
I am trying to build a spring-mvc project that has another project (core, as .jar) as dependency.
If I disable "Resolve dependencies from workspace projects" in eclipse, install the core into my maven repo and run it from eclipse, the application works!
What I want to do, is re enable "Resolve dependencies from workspace projects", but there is the problem: When I try to run the project on tomcat (after maven clean, project clean), I get a "FileNotFoundException". The file in question is under src/main/resources/META-INF/spring/applicationContext-core.xml
It seems, the File can not be found in the classpath.
I looked up the deployment location and found out, that everything of the core is under the following folders:
WEB-INF
classes
So the file I am missing can be found here:
/WEB-INF/classes/META-INF/spring/applicationContext-core.xml
But it schould be here:
/META-INF/spring/applicationContext-core.xml
Why is the structure of my core dependency so messed up when I enable the workspace resolution and how can I fix this?
I am using eclipse mars with m2e..
Thanks for any help.
Edit:
Project structure (core) looks like this:
project structure
I am using Eclipse Kepler for Java. Normally you can add internal/external .jars to a Java project in the build path located in the properties. Why, when I clone a git repo and import it into my projects, do I lose that ability? I don't understand. I kinda need to do that.
This is probably because the .gitignore has been configured to ignore .jar
Open the .gitignore file and remove the line *.jar, you should be able to add it.
======
As an aside - usually, for Java projects .jar files are not committed to repository (as they are large & it can slow down repository cloning), instead maven or gradle is used to configure dependencies. Example - http://www.mkyong.com/maven/how-to-create-a-java-project-with-maven/
Then when you want to work with eclipse just run mvn eclipse:eclipse to generate the necessary files. .gitgnore is usually set up to ignore *.class, *.jar, .project, .settings, .classpath
I found that if you open the run configurations and go to the Classpath tab that you can add internal/external .jars. The run configuration can be accessed by clicking Run > Run configurations. I added my .jar to the user entries. The bootstrap entry caused a null pointer.
When a project relies on libraries/modules, it's best to use a build tool for dependency management. JVM ecosystem is dominated with three build tools: Gradle, Maven and Ant.
How it works:
In a build script we declare dependencies of the project. This tells the build tool where to retrieve libraries/modules our project depends on. Dependencies are resolved at runtime; downloaded from a remote repository, retrieved from a local directory or if required another project to be built in a multi-project setting.