3.6: External Jars in a Dynamic Web Project [message #544731] |
Mon, 05 July 2010 07:45  |
Eclipse User |
|
|
|
What is the right way to use external libraries from within a Dynamic Web Project?
I have a super-clean minimal setup:
* new Eclipse WTP 3.6 64-bit, official distribution, no other plugins
* new workspace
* new Tomcat 6.26, only unpacked, no other modifications
* new Server Runtime, no modifications, default settings
* new Dynamic Web Project, default settings
* new JSP page saying "hello"
* Add to Server, Run
Until here it works fine!
Now I want to use Log4j:
* Build Path > Add External JARs...
* Browse and select the Log4j Library
* new Servlet, default settings
* print a logging statement in doGet()
* restart the server
* open the Servlet URL in the Browser
ClassNotFoundException: org.apache.log4j.Logger
The project is published, but WEB-INF/lib is empty.
Then I found the "Deployment Assembly" page under Project Properties.
* Add.. > External Archive
* Browse and select the Log4j Library
* Restart Server
Now it works. WEB-INF/lib contains log4j.jar.
Nothing else in "Deployment Assembly" works.
Configuring the external libraries in both the Build Path and Deployment Assembly seems so redundant. Is this the right way to use external libraries?
This took me 2 days of trial/error with every setting imaginable. It is part of an effort to get a Maven Project deployable with WTP.
|
|
|
|
Re: 3.6: External Jars in a Dynamic Web Project [message #544821 is a reply to message #544815] |
Mon, 05 July 2010 11:45  |
Eclipse User |
|
|
|
My goal is to avoid maintaining dependency information anywhere else than in the Maven pom.xml. Our dependency graph includes directly 40+ and transitively 110+ dependencies and changes in dependencies or versions would require precise housekeeping of the User Library.
So far I found this partial solution. It works when used with Maven and the m2eclipse plugin:
0) clean everything that is Eclipse-related - delete .project .classpath .settings .externalToolBuilders. Eclipse will not recognize this as a project now.
1) In the terminal run
mvn -Dwtpversion=2.0 eclipse:eclipse
This will generate the Eclipse configuration and make it a Dynamic Web Project. The generated files will not be up to date with the current but WTP 3.2 which is integrated in Eclipse 3.6, but Eclipse/WTP will understand it. This will also populate the list in the Deployment Assembly page in Project Properties.
2) Refresh the project in Eclipse. It should be recognized as a Dynamic Web Project now.
3) Maven > Enable Dependency Management
This will enable the m2eclipse plugin and recognize it as a Maven Project.
When some dependency or version of dependency changes, you have to repeat from 1) to 3).
|
|
|
Powered by
FUDForum. Page generated in 0.03922 seconds