简体   繁体   English

自动将新的Jar文件复制到Tomcat项目WEB-INF / lib文件夹中

[英]Automatically copy new Jar file to Tomcat project WEB-INF/lib folder

I am developing a Tomcat app (actually it's a Red5 app, but this is effectively the same). 我正在开发Tomcat应用程序(实际上它是Red5应用程序,但这实际上是相同的)。

This contains the usual /WebContent/WEB-INF/lib folder, which is where I locate the various jars it uses. 它包含通常的/ WebContent / WEB-INF / lib文件夹,在这里可以找到它使用的各种jar。

Recently, I pulled a package out of my app project, and converted into a separate Jar project which was then released as open source (this resides in the same workspace). 最近,我从我的应用程序项目中提取了一个程序包,并将其转换为一个单独的Jar项目,然后将该项目作为开源发布(驻留在同一工作区中)。

What I want, is that when I build my Tomcat app, that Eclipse automatically pulls the latest version of the Jar I have built into its /WebContent/WEB-INF/lib folder. 我想要的是,当我构建Tomcat应用程序时,Eclipse会自动将我构建的最新版本的Jar放入其/ WebContent / WEB-INF / lib文件夹中。

This is the behaviour you get with .NET when you reference one project from another, and I guess this is why I was expecting to find some way of doing it. 这是当您从另一个项目中引用一个项目时,.NET的行为,我想这就是为什么我期望找到某种方式来实现它的原因。

At the moment, I have to manually copy/paste the Jar across each time I build it. 目前,每次构建时,我都必须手动复制/粘贴Jar。

Of course, ideally when I build my Tomcat app it would automatically detect if the Jar project was up-to-date too, and build it if not. 当然,理想情况下,当我构建Tomcat应用程序时,它会自动检测Jar项目是否也是最新的,如果不是,则进行构建。

Any suggestions most gratefully received. 非常感谢收到任何建议。

I have been trying to do this now - and I've almost got it working. 我一直在尝试执行此操作-而且我几乎可以正常运行了。 I have 3 class libraries that I want in the WEB-INF/lib directory, so I created custom Ant builder rules for each of the class library eclipse projects to create the lib/ classlib .jar file whenever the project sources change (search for 'Creating a project builder Ant buildfile' in the Eclipse help). 我在WEB-INF / lib目录中有3个类库,因此我为每个类库eclipse项目创建了自定义的Ant构建器规则,以便在项目源发生更改时都创建lib / classlib .jar文件(搜索“ Eclipse帮助中的“创建项目构建器Ant buildfile”。

I then added each of these jar files (it's not sufficient to add just the project references) to the 'Java EE Module Dependencies' section of the web project. 然后,我将每个jar文件(仅添加项目引用还不够)添加到Web项目的“ Java EE模块依赖关系”部分。

When you export the web project they will appear in the .war file. 导出Web项目时,它们将显示在.war文件中。 I haven't found a way of getting them into it without having to export (I want to debug in-place rather than deploying the .war file). 我还没有找到一种无需导出就可以将它们放入其中的方法(我想就地调试而不是部署.war文件)。

I have to agree with systempuntoout that the most likely solution is to use an Ant builder. 我必须同意systempuntoout的观点,即最可能的解决方案是使用Ant构建器。

Edit: Ant copy tasks work. 编辑:Ant复制任务正常工作。 Add a file called copylibs.xml to the root directory of the web project: 将一个名为copylibs.xml的文件添加到Web项目的根目录中:

<?xml version="1.0" encoding="UTF-8"?>
<project name="copylibs" default="copylibs" basedir=".">

    <target name="copylibs" description="Copy dependent jar files">
        <copy file="../com-aaaa-util/lib/com-aaaa-util.jar" todir="webroot/WEB-INF/lib/" />
        <copy file="../com-aaaa-mnp/lib/com-aaaa-mnp.jar" todir="webroot/WEB-INF/lib/" />
        <copy file="../com-aaaa-bbbb/lib/com-aaaa-bbbb.jar" todir="webroot/WEB-INF/lib/" />
    </target>
</project>

Then add an Ant builder to do this during a build. 然后添加一个Ant构建器以在构建期间执行此操作。

I would go with build tools like: 我会选择以下构建工具:
1. Ant using File Tasks 1. Ant使用文件任务
2. Maven . 2. Maven

You can configure Eclipse WTP to automatically assemble the web application right from Eclipse workspace without copying any jars. 您可以将Eclipse WTP配置为直接从Eclipse工作区自动组装Web应用程序,而无需复制任何jar。 This way your changes in dependent project would be immediately reflected in the deployed web application. 这样,您对从属项目的更改将立即反映在已部署的Web应用程序中。

As an alternative, you can use Ant or Maven script to copy jars where you want. 或者,可以使用Ant或Maven脚本将jar复制到所需的位置。 With Maven you pretty much get it for free without writing any script or additional configuration. 使用Maven,您几乎可以免费获得它,而无需编写任何脚本或其他配置。

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

相关问题 WEB-INF / lib中的Tomcat自定义库jar文件 - Tomcat custom library jar file in WEB-INF/lib 将Jar文件添加到WEB-INF / lib - Adding Jar File to WEB-INF/lib tomcat / lib或WEB-INF / lib中不需要的jar文件 - Unwanted jar files in tomcat/lib or WEB-INF/lib 如何从远程服务器为位于apache-tomcat WEB-INF / lib文件夹下的jar文件制作下载URL? - How to make a download url for the jar file located under apache-tomcat WEB-INF/lib folder from remote server? Eclipse:无法将jar加载到Tomcat WEB-INF / Lib文件夹中? - Eclipse : Unable to load jar's into the Tomcat WEB-INF/Lib folder ? 在eclipse中运行tomcat时,不会从WEB-INF / lib中的jar文件加载spring web应用程序上下文 - spring web application context is not loaded from jar file in WEB-INF/lib when running tomcat in eclipse Maven,GWT,Google Eclipse插件,在依赖项项目处于战争状态时无法将jar复制到WEB-INF / lib - Maven, GWT, Google Eclipse plugin, can not copy jar to WEB-INF/lib when dependency project is war 在`WEB-INF / lib`文件夹中找不到jar文件的解决方案,也没有在`src / main / resources`文件夹中找到? - Solution for a jar file not findable in the `WEB-INF/lib` folder nor `src/main/resources` folder? 如何使用Grunt将jar文件复制到WEB-INF / lib - How to copy jar files to WEB-INF/lib using Grunt 为什么Tomcat库文件夹WEB-INF / lib是空的? - Why Tomcat library folder WEB-INF/lib is empty?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM