I am using Eclipse m2e plugin to import existing web app to Eclipse. And Tomcat is used to deploy the web app. I run the Tomcat from Eclipse' Servers list.
And everything works fine except when I got ClassNotFoundException when I tried to Run the project on Tomcat Server. The not found class is a class from another m2e project which is depended by the web app project.
And I navigated into the web app deployment folder like
$EclipseWorkspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/MyApp/WEB-INF/lib
and found out the jar containing complained not found class was indeed generated in WEB-INF/lib. But the jar was in weird layout.
The layout was like below
src/main/java/com/mycompany/xxx.java
target/classes/com/mycompany/xxx.class
but not expected
com/mycompany/xxx.class
I looked into the Deployment Assembly section of the web app properties, everything was fine.
Why the Eclipse(or the m2e plugin) generates wrong formatted JAR files?
I was using maven Eclipse plugin to generate .classpath, .project files and .settings/ folder for Eclipse, via
mvn eclipse:eclipse
.
I didn't clean all these Eclipse
.classpath file
.project file
.wtpmodules file
.setting folder
before I used Eclipse m2e plugin.
At the end I deleted all these
.classpath file
.project file
.wtpmodules file
.setting folder
.
And re-import all the maven projects to Eclipse using m2e plugin.
Then the issue I mentioned was gone! All jars are now in good shape!
Looks like the existing Eclipse files causes the m2e plugin not happy, and generated unexpected result.
Related
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 working with Eclipse Luna.
I have a dynamic web project into my workspace: project-web. This project depends on another project into my workspace: project-lib.
So I get this scenario: project-web[:war] ---depends on--> project-lib[:jar]
I have checked "Resolve dependences from workspace projects" option into Properties -> Maven for the web project.
When I run "mvn clean package" for project-web Maven creates war file into the target directory but I have
an issue. If I explode the war file, I find an empty folder called "project-lib" into the WEB-INF/lib directory.
Since the library is empty I get some java exceptions on Tomcat startup.
How to create the war for project-web correctly?
Thanks in advance.
Enrico
My project refers to the generated pom.properties file that Maven generates in:
META-INF/maven/${groupId}/${artifactId}
Which is included (in a Jar) as a dependency in another project. When I build / package the main project with Maven outside of Eclipse, the dependency Jar is built as expected (containing the pom.properties file) and all is well.
However, when I build / run the same (parent) project within Eclipse, it's not there. What am I missing?
Using Eclipse, a Jar library of the dependency is there (in the lib folder), containing everything except the Maven generated files. So in my case:
META-INF/
META-INF/persistence.xml
META-INF/MANIFEST.MF
~~~ snip ~~~
The dependency project exists in the same workspace and I have "Workspace Resolution" enabled.
Looking at the build target folder in Eclipse (\target\classes), I can see all the files that Eclipse uses for the Jar, so I can only assume that Eclipse treats it as a "regular" Java project (despite the parent project listing it as a Maven dependency in the POM) - so Maven doesn't get involved in the packaging.
How can I get Eclipse to treat the project dependency as a Maven project / so that the generated pom.properties will be included in the Jar used by the parent project?
Update
For the parent (War) project, the following structure is generated whenever I use Eclipse to build the project (using "Build Project" or "Build Automatically" not "Maven build"):
target\m2e-wtp\web-resources\META-INF\maven\${groupId}\${artifactId}\pom.properties
This is referenced in the Eclipse deployment assembly:
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
So that when the War is deployed to Tomcat, the META-INF\maven... structure exists at the root of the archive.
The dependency / Jar project obviously has the same "Deployment Assembly" facility in Eclipse, so I just need to figure out what creates the m2e-wtp folder on build and apply it to that project too.
Actually, I don't think you can with the default Eclipse Jar-Export.
The best you can do if you want to do it from within Eclipse is to have a Maven Build run configuration which doesn't do much differently than using Maven outside Eclipse. But at least you have a button in Eclipse to click do generate the jar, if that's the main reason. But the normal Eclipse functionality to produce a jar (File > Export...) ignores all Maven settings.
Workspace Resolution only works for compiling and running code, but not for other Maven functionality.
I import a project to my workspace and convert it to Maven project using m2e and ran the pom file with goal specify "clean install".
But my project build path is not populating with the jars already downloaded to my local repository which still gives compilation errors in the source.
When i expand "Maven Dependency" variable in the library tab of build path, i can not see the jars already downloaded?
Was there existing Eclipse metadata when you imported the project, perhaps from another developer? This is a frequent cause of failure in Eclipse, especially if you have metadata from the earlier m2eclipse plugin.
I have encountered the situation many times (in Juno and Kepler) where the .classpath is incorrect, resulting in the symptom you describe, and I either have to rewrite the .classpath myself or nuke it and encourage Eclipse to try again.
In your case:
delete the project from your Eclipse workspace (but not the filesystem)
delete the subdirectories .settings and target, and the files .classpath and .project from the project directory
re-import the project into Eclipse via File -> Import... -> Existing Maven Project
The Eclipse dot-directories will be created from scratch, and the project should already be configured as a Maven project; artifact retrieval should start in the background.
If this fails, check the 'Maven Console' in Eclipse for clues, and/or the Eclipse Error Log.
As other people have commented, you need to ensure that your m2 settings file is being correctly interpreted by m2e.
Can you build successfully from the command line?
I got an Maven project which is compiled in Eclipse. Now I need to migrate it to a Linux environment, and there won't be GUI interface I can use. I wonder what I should do to migrate it?
Currently , under Eclipse project folder I have the files/folders as the below:
.classpath
.project
.settings
.springBeans
doc
pom.xml
src
target
I figure all those .* folders are Eclipse meta data. so I can remove them. Then I can use the rest to form a Maven project that I can build using Maven command lines?
For a maven project to work command line, all you need is
Maven is installed and correctly exported in the $PATH variable
The pom.xml in your workspace.
Just go to the project directory and run mvn install.
mvn clean
then remove .project .classpath
if you want to lose eclipse project settings while migrating delete .settings (assuming it doesn't have machine specific path/settings)
copy rest to new linux environment
open eclipse, import project as maven project (assuming you have new eclipse with maven plugin setup on linux environment)
Note:
make sure you still have a backup before you successfully migrate over
.classpath contains references to local .m2 when used with eclipse and maven so the path would differ in linux and would create issue
.project contains some configuration that is eclipse maven plugin dependent, so it is good to loose it once and let new environment create new one