简体   繁体   English

在Eclipse部署程序集中将Web项目添加为jar

[英]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. 我现在正在工作的站点由几个Java项目和一个引用它们的主Web项目A组成。 The IDE I'm using is Eclipse Helios. 我正在使用的IDE是Eclipse Helios。

What I'm trying to accomplish is adding a new project B to the stack. 我要完成的工作是将一个新项目B添加到堆栈中。 The project is also referenced by the main one, but is in itself a Web Project. 该项目也被主要项目引用,但它本身就是一个Web项目。 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 . 当我将B添加到A的Deployment Assembly中时,发布时,Eclipse会自动将其打包为war,并将其部署到服务器的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. 我希望将其部署为jar,还希望保留项目的网络性质,因为它具有在其上运行的某些功能(和测试)。 I have ant tasks in place for building a jar out of B , but I don't know how to use them in Eclipse. 我已经完成了一些用B构造jar的蚂蚁任务,但是我不知道如何在Eclipse中使用它们。 Also, I'm not sure if it's possible to make Eclipse deploy a jar out of a web project. 另外,我不确定是否有可能使Eclipse从Web项目中部署jar。

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. 我可以手动添加jar(作为工作空间中的存档),但这意味着每当有人清理所有项目时, B的jar就会被删除而不生成,因为构建仅编译类并将部署将其打包到战争。

PS I know the design is poor, but changing it is out of the question as I don't have the authority :). PS 我知道设计很差,但是更改它是不可能的,因为我没有权限:)。

I found the following solution that works for me on Eclipse Luna 我发现以下适用于Eclipse Luna的解决方案

  1. Project B "Project Facets" : select "Utility Module" instead of "Static Web Module" or "Dynamic Web Module" 项目B“项目方面”:选择“实用程序模块”而不是“静态Web模块”或“动态Web模块”

  2. Project A "Deployment Assembly" : remove "B" and add it another time. 项目A“部署程序集”:删除“ B”,然后再添加一次。

=> The "Deploy Path" of B is now B.jar => B的“部署路径”现在是B.jar

The easiest way is: File -> Export... -> Java -> Jar File 最简单的方法是:File-> Export ...-> Java-> Jar File

To use ant: open project properties, the go to Builders, Click new, selec Ant Builder, etc. 要使用ant,请打开项目属性,依次转到Builders,单击new,selec Ant Builder等。

You can do something like this: 您可以执行以下操作:

  1. Write a shell/batch script that 编写一个shell /批处理脚本
    • calls ANT script of project B which creates a JAR file. 调用项目B的ANT脚本,该脚本创建一个JAR文件。
    • and then, it calls ANT script of project A. 然后,它调用项目A的ANT脚本。
  2. Update ANT script of project A, add a copy task. 更新项目A的ANT脚本,添加复制任务。 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. 此文件复制任务将使用相对路径将在步骤1中创建的JAR文件复制到项目A的WEB-INF / lib目录。
  3. In Eclipse, go to External Tool > External Tools Configuration > Program > New Progam and add this Shell/Batch script to it. 在Eclipse中,转到“ External Tool > External Tools Configuration > Program > New Progam然后向其中添加此Shell / Batch脚本。

Whenever you want to build. 每当您要构建时。 Run this external tool from menu.This will ensure 从菜单运行此外部工具。这将确保

  • Your build always has the latest of Project B 您的构建始终具有最新的Project B
  • ANT tasks will stay small. ANT任务将保持很小。

Adding a Web Project in an Eclipse Deployment Assembly 在Eclipse部署程序集中添加Web项目

I did not know any such thing, until Thorbjørn Ravn Andersen pointed this out in another question where I answered . 我不知道这样的事情,直到ThorbjørnRavn Andersen在另一个我回答的问题中指出了这一点。 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. 部署中的内容不取决于构建路径,而是取决于动态Web项目的“首选项”中的“部署程序集”条目。

But, may be, you have already tried this. 但是,也许您已经尝试过了。


Edit#1: fixed grammar Edit#2: added more info 编辑#1:固定语法编辑#2:添加了更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM