Adding a Web Project as a jar in an Eclipse Deployment Assembly
The site I'm working on now is made up of several java projects and a main web project A
which references them. The IDE I'm using is Eclipse Helios.
What I'm trying to accomplish is adding a new project B
to the stack. The project is also referenced by the main one, but is in itself a Web Project. When I add B
to the Deployment Assembly of A
, when publishing, Eclipse automatically packages it as a war and deploys it to the server's WEB-INF/lib
.
I want it to be deployed as a jar, but also keep the project's web nature, as it has some features (and tests) that are run on it. I have ant tasks in place for building a jar out of B
, but I don't know how to use them in Eclipse. Also, I'm not su开发者_JAVA技巧re if it's possible to make Eclipse deploy a jar out of a web project.
I can add the jar manually (as an archive from the workspace), but that would mean that whenever someone cleans all projects, the jar for B
would get deleted and not generated, as the build only compiles the classes and the deploy packages them into the war.
P.S. I know the design is poor, but changing it is out of the question as I don't have the authority :).
I found the following solution that works for me on Eclipse Luna
Project B "Project Facets" : select "Utility Module" instead of "Static Web Module" or "Dynamic Web Module"
Project A "Deployment Assembly" : remove "B" and add it another time.
=> The "Deploy Path" of B is now B.jar
The easiest way is: File -> Export... -> Java -> Jar File
To use ant: open project properties, the go to Builders, Click new, selec Ant Builder, etc.
You can do something like this:
- Write a shell/batch script that
- calls ANT script of project B which creates a JAR file.
- and then, it calls ANT script of project A.
- Update ANT script of project A, add a copy task. This file copy task will use relative path to copy the JAR file created in step#1 to project A's WEB-INF/lib directory.
- In Eclipse, go to
External Tool > External Tools Configuration > Program > New Progam
and add this Shell/Batch script to it.
Whenever you want to build. Run this external tool from menu.This will ensure
- Your build always has the latest of Project B
- ANT tasks will stay small.
Adding a Web Project in an Eclipse Deployment Assembly
I did not know any such thing, until Thorbjørn Ravn Andersen pointed this out in another question where I answered. As mentioned there:
What goes in the deployment is determined not by the build path but by the Deployment Assembly entry in Preferences for the dynamic web project.
But, may be, you have already tried this.
Edit#1: fixed grammar Edit#2: added more info
精彩评论