Adding a Web Project as a jar in an Eclipse Deployment Assembly

久未见 提交于 2019-12-06 13:26:18

问题


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 sure 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 :).


回答1:


I found the following solution that works for me on Eclipse Luna

  1. Project B "Project Facets" : select "Utility Module" instead of "Static Web Module" or "Dynamic Web Module"

  2. Project A "Deployment Assembly" : remove "B" and add it another time.

=> The "Deploy Path" of B is now B.jar




回答2:


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.




回答3:


You can do something like this:

  1. 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.
  2. 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.
  3. 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



来源:https://stackoverflow.com/questions/4657304/adding-a-web-project-as-a-jar-in-an-eclipse-deployment-assembly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!