Eclipse Luna, m2eclipse: empty dependency when dependency is a workspace project - java

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

Related

Why Eclipse m2e plugin deploy wrong formatted jars to Tomcat server

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.

Eclipse, Tomcat & Maven workspace resolution: wrong folder structure?

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

Jar missing generated pom.properties file when built in Eclipse

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.

Java build path not updated with pom dependencies

I updated the pom.xml to spring 3.0.1.RELEASE instead of Spring 2.x.x .
So when I did 'mvn clean install', the lib directory in my target directory was correctly updated with the right jar files.
But when I do a right click on my project and then go to "Build Path", I notice that I have the old dependencies of spring and not the dependencies for spring 3.0.
How can I update the Java Build Path?
If this is eclipse (you are using), then you need to update the Eclipse project file from the .pom file. That is done by doing the following command:
mvn eclipse:eclipse
After that, refresh project in eclipse and you will see that eclipse recognises the dependencies from the pom file.

Jars not copied to Tomcat's lib folder

I am doing some basic spring stuff and stuck at some point.
I am getting ClassNotFoundException whenever I deploy my application on Tomcat.
I observed that the jars are not copied to Tomcats lib folder.
When I copied the jars manually to Tomcats lib folder it works fine.
Please let me know if I am making any blunder.
PS - I am using Spring tool suite 2.6.0,Tomcat 6 and its a Maven project.
Thanks.
Go to "Project properties -> Deployment Assembly page".
This page describes how your application will be packaged for deployment or export. And added new source "Maven dependency".
From Deployment Assembly page, Click Add... button
Then select "Java Build Path Entries"
"Maven dependency" should be in the list
It solves the issue and all jar got copied to tomcat
If you define "war" packaging for your maven project then your dependent libraries should be automatically copied to the WEB-INF/lib directory of the created .war file by the Maven WAR plugin.
Put your jars in the WEB-INF/lib directory:
In Project properties -> Deployment Assembly you should have a Source of /web with a Deployment Path of /. If this is there then any jars in the web/WEB-INF/lib directory will get deployed and picked up by the class loader. Note that sub-directories will not be picked up though, so put your jars directly in the lib directory.
You run three command in cmd or bash(where your pom.xml file placed) to get jar file and copy it into your WEB-INF/lib folder
mvn compile
mvn package
mvn install
I find only this way for resolved my problem:
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

Categories

Resources