copy libs into web archieve - java

I have an eclipse project in which dependent jars are in a separate folder called libs.
Is there a way in eclipse to configure all the jars in lib folder to be copied into webarchieve's lib folder automatically when I export the war file from eclipse or debug it on server?
I am using tomcat 7 as server runtime.

Sure, just go to the
project properties -> Deployment Assembly -> Add -> Archives
Any archive that you add this way to dynamic web project would be copied to WEB-INF/lib folder.

Related

Eclipse java web project manual set lib folder in WEB-INF

I checked out a project from svn. The project have a folder named as "ws" which contains WebContent folder. But the lib folder is outside the WebContent folder and under another folder under "ws" folder. I found out I have to move the lib folder to WEB-INF folder in WebContent folder, so eclipse can find the libraries I need.
Would anyone show me how to manually set the path so eclipse can load the libraries from the original lib without moving the lib to WEB-INF?
Thanks
You can edit the Deployment Assembly which controls how the app deployment is assembled. Right-click the project and select Properties; select Deployment Assembly and then use Add... to include your project's libraries (JARs) in the deployed WEB-INF/lib folder.
If you've already included the libraries on the project Build Path, there's an option in the Add... dialog to include them directly. Otherwise you can just add a folder itself.

Configure Tomcat webapps directory as per project's output folder structure

My project's output folder structure is webapps\WEB-INF\classes. Here War file get all the content inside webapps folder. But when I build my project, tomcat only takes content inside under webapps\WEB-INF\classes folder. So in Tomcat's webapps folder <contextRoot>/content of classes folder. I want to configure to be <contextRoot>/content under webapps folder.
IDE is Eclipse Juno 3.6 and tomcat 6.0 server.
If your project is a Dynamic Web Project, you can configure those settings in the Deployment Assembly in your project properties. (Right click your project -> Properties -> Deployment Assembly.)
Hope this helps.

eclipse, wtp and tomcat configuration for source folder

I have a java project in eclipse which is having jar file reference of other projects.
Now, I have removed those jar files and added projects in eclipse, no compilation error in eclipse. I have configured Tomcat server in eclipse.
But server doesn't get loaded when i add project instead of jar files.
I have observed following path in eclipse workspace:
<<Eclipse IDE workspace>>\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\ESW\WEB-INF
under WEB-INF folder, jar files and class files are located. All jar files are loaded to 'jar' but under classes folder no class files are present at this directory. here i am expecting class files of the project which i have added in source folder instead of jar files. how can i do it?
Please try to use the Deployment Assembly option (Project Properties ---> Deployment Assembly ) to configure which files to be deployed to the WTP Tomcat . Before eclipse 3.5 or before , this option is called something likes J2EE Module Dependencies
Deploy path is relative to the your <<Eclipse IDE workspace>>\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\ESW\ while source path is relative to your project folder.

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

Referenced libraries not being deployed by Eclipse

I setup a Google App Engine project in Eclipse. I added a root level folder to contain libraries for my project. I added all of these libraries to the build path for my project. The code compiles without any errors. When I run the project, I get startup errors NoClassDef errors. When I add these libraries manually to the war directory's lib folder, these errors disappear.
Why isn't Eclipse deploying the libraries on my build path for me? Do I need to have a build script in place for Eclipse to run? A build script that will copy my libraries to the war dir's lib folder?
For standard Java EE project libraries have to be under {web-app}/WEB-INF/lib folder. GAE requires them to be there too to upload to the engine with your code.
Alternatively you can use Maven to define your dependencies and deploy to GAE
UPDATE: GAE project follows standard Java EE project structure to build and deploy a war file. The convention is that your lib folder is in {web-app}/WEB-INF/lib. Google plugin automatically generates such a structure (example from plugins docs):
MyTestProject
src/
log4j.properties
META-INF/
jdoconfig.xml
com/
mytestproject/
MyTestProjectServlet.java
war/
index.html
WEB-INF/
appengine-web.xml
web.xml
logging.properties
classes/
lib/
...App Engine JARs...
The plugin does allow to change location for your "war" directory, but not the location of your libraries since it should follow the Java EE standard.
You can add the libraries to your war/lib directly, and then right click on the libraries to add them to your build path.
Not sure why it doesn't deploy libs on your build path, but I have been working with Eclipse for years and have always done it the way I described. Then I just deploy through eclipse and don't use a build script.
If the library which was not added to lib folder is being developed in the same workspace, I would suggest to enable the "Utility Module" facet in project properties of the library project. Sometimes Eclipse doesn't copy a jar into WEB-INF/lib folder even if the Deployment Assembly and everything else was configured properly.

Categories

Resources