Spring maven dependencies not copied in the WEB-INF/lib folder - spring

I have a working GWT-App Engine web project which works before I added the Spring dependency in the POM. Now when I run the application, this error is thrown (and ultimately App engine won't load):
java.lang.ClassNotFoundException:
org.springframework.web.context.ContextLoaderListener
I think the problem is that the Spring jars are not copied to the WEB-INF/lib folders as I can't see those in that folder.
Any ideas how Spring jars will be copied to that folder?
Update:
Here's the complete POM.xml

Add <packaging>war</packaging>. Currently Maven doesn't copy any dependencies artifacts into WEB-INF/lib because that's a default behaviour of jar packaging you used so far for this artifact.

I think you should add
<packaging>war</packaging>
after
<groupId>mygwtapp</groupId>
<artifactId>mygwtapp</artifactId>
<version>0.0.1-SNAPSHOT</version>

Add them as Maven dependencies to your war and make sure their scope is not "provided".

Related

Why there is a pom.xml for all jars in mave repository

In the maven repository, there is a pom.xml corresponding to every jar. What is the use of that pom.xml.
How important is that pom.xml and will the execution work without that pom.xml ? Thanks in advance.
Each of those jars is a project (somewhere) that was built using Maven - hence the need for a pom. Also, the pom describes all the transitive dependencies for any jar that your project needs. Those files are important, and your project cannot build without them.

WildFly - Adding JARs to classpath

I am using WildFly 8.2.1.
I need to add specific JAR files to the class path. How can I do that?
Do I need to get inside the module hell?
All I need is to add a couple of extra Oracle JAR files to enable using TLS on the data source connection...
When you build your .war file, add them to the /WEB-INF/lib directory. They will be accessible on the classpath from there. In eclipse the eclipse maven plugin, m2e, will do it by reading your POM file, or of course, maven run by hand will do it.
In the POM file, have it packaged as a war
<packaging>war</packaging>
and declare your jar as a dependency.

Using jars which have no dependency tag in Maven's pom.xml

I have a web application which needs to be converted to Maven for building and deploying.
I was able to find dependency to add in pom for most of the jars but was not able to find dependency tag for few jar files.
How do I add these jars to my application so that my application compiles ?
Can I add these jars for Maven from web-inf/lib or some other location ?
You can install jars manually to your maven repository using the maven-install-plugin:
http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

Java Maven Project appears in another project as directory not a jar

So, I created a Spring Maven Project, a Dao Project, which works great. All the code is in the correct place, all the unit tests run, and I can do a mvn clean install. I can see in the target directory that there is a build jar, and everything in it looks fine. I can also confirm that when I check my local .m2/repository, the latest jar I just built is in there.
Here is a small segment of that pom.xml:
<modelVersion>4.0.0</modelVersion>
<groupId>com.tom.myproject</groupId>
<artifactId>myproject-dao</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>My Project DAO</name>
Now, I am creating a new Spring Maven Web-Project for my UI, and this pom.xml starts out like:
<modelVersion>4.0.0</modelVersion>
<version>0.0.1-SNAPSHOT</version>
<groupId>com.tom.myproject</groupId>
<artifactId>myproject-ws</artifactId>
<name>My Web Project</name>
<packaging>war</packaging>
Also in this pom.xml file, one of the first dependencies I have is:
<!-- My DAO ProjectDependencies -->
<dependency>
<groupId>com.tom.myproject</groupId>
<artifactId>myproject-dao</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
I can see in eclipse that when I try to access the classes from this dao jar, that seems to work fine. When I compile the code here, that all works fine. And when I do a "mvn clean install" to build this war, I can see the target directory, and all the needed classes and jars come in, obviously there are hibernate, logging, and spring classes that are there in the WEB-INF/lib directory.
Now this is he part where the question comes in ... Why does the myproject-dao show up under WEB-INF/lib as WEB-INF/lib/myproject-dao-0.0.1-SNAPSHOT.jar but appears as a directory, and not a jar?
Certainly when I pull in other jars, they are just .jar files and not directories.
I should add, when you look in the Eclipse project under maven dependencies, the icon for all the other jars show them as files. The icon for my myproject-dao.jar uses the icon for a folder/directory, so clearly a directory named "myproject-dao.jar" is being created and not a file with zipped up contents into a jar file.
When I build the war file, and deploy the war, the app says it cannot find any of the classes in the myproject-dao.jar directory. I have to delete the FOLDER "myproject-dao.jar" from the WEB-INF/lib directory and manually copy over the FILE "myproject-dao.jar". I can then clearly see the icon that means this really is a file.
This is probably a simple fix, so if you can help me out, that would be great.
ANSWER:
I wasn't using the maven-assembly-plugin. But, I did find out what the problem is.
Both my DAO project and the WEB project are in the same workspace, and the DAO project was open, as a result, the maven dependency shown in Eclipse was a folder icon, and not the jar icon. When I closed the DAO project and looked back at the maven dependencies on the WEB project pom.xml file ... NOW it shows the icon as a jar and not a folder.
So, all I have to do build my dao.jar file with maven, and when it is successful, it is done.
Then I have to CLOSE the project within Eclipse.
In my web project pom.xml file, the icon will now show this as a jar file, and when it builds, it will pull in the jars.
I imagine this is a benefit if one is working on several prior project, you really do have the chance to look at what is in the jar file while the war is running.
In my case, I know my dao.jar is working, so I can build it, and close the project, and then make use of that jar anywhere I need it.
I wasn't using the maven-assembly-plugin. But, I did find out what the problem is.
Both my DAO project and the WEB project are in the same workspace, and the DAO project was open, as a result, the maven dependency shown in Eclipse was a folder icon, and not the jar icon. When I closed the DAO project and looked back at the maven dependencies on the WEB project pom.xml file ... NOW it shows the icon as a jar and not a folder.
So, all I have to do build my dao.jar file with maven, and when it is successful, it is done.
Then I have to CLOSE the project within Eclipse.
In my web project pom.xml file, the icon will now show this as a jar file, and when it builds, it will pull in the jars.
I imagine this is a benefit if one is working on several prior project, you really do have the chance to look at what is in the jar file while the war is running.
In my case, I know my dao.jar is working, so I can build it, and close the project, and then make use of that jar anywhere I need it.
Thanks for the help!

Spring AppContext in Maven

I am using Maven for creating my project structure. The following is the way I am doing
Generate Archetype
Have the following modules - Ear, War and WarSource (I am deleting the src, ejb and jar folders)
So my EAR will have 2 modules - War and WarSource which inturn have src/main/java and src/main/resource folders
Question is - where should my application context reside so that I avoid the File Not Found error during runtime.
Thanks
If you're using spring mvc it will be in the war src/main/webapp/WEB-INF/ directory. Also if you're using spring you may not even need an ear file, you should read up on that to be sure you're not adding unnecessary complexity.

Resources