如何将所有依赖项部署到我的 build.xml 中的 tomcat
how to deploy all dependencies to tomcat in my build.xml
我在 build.xml
中有一个技巧,可以将所有依赖项下载到缓存中:
<target name="init" depends="init-ivy">
...
<ivy:cachepath
inline="true"
module="jersey-container-servlet"
organisation="org.glassfish.jersey.containers"
pathid="jersey.classpath"
revision="2.23.2"/>
<ivy:cachepath
inline="true"
module="javax.json"
organisation="org.glassfish"
pathid="json.classpath"
revision="1.0.4"/>
...
</target>
代码编译成功并创建了一个 war
文件。现在我需要编写一个任务来将应用程序部署到 tomcat。我需要将所有依赖项复制到应用程序的 WEB-INF/lib
。这是怎么做到的?也许有一种方法可以将依赖项的 JAR 包含到 WAR 文件中?我是 Java 开发的新手,请帮忙。
以下答案概述了使用 ivy file 的综合解决方案。
它回答了一个不同的问题("provided" 依赖项),但你最终会遇到这个问题,因为并不是你在构建中使用的所有 jar 都需要随你的应用程序一起提供(因为它们已经存在于 tomcat).
尝试将此答案应用于您的问题并不简单,因为您正在以内联模式(无 ivy 文件)解析依赖项。首先,我建议将您的依赖项组合到一个路径中,而不是围绕每个依赖项创建路径:
<ivy:cachepath pathid="compile.classpath">
<dependency org="org.glassfish" name="javax.json" rev="1.0.4" />
<dependency org="org.glassfish.jersey.containers" name="jersey-container-servlet" rev="2.23.2" />
</ivy:cachepath>
其次(并回答你的问题),它是备用常春藤 retrieve task that's used to place ivy files on the file system. It too can support an inline resolution 如下:
<ivy:retrieve pattern="${build.dir}/lib/[artifact].[ext]">
<dependency org="org.glassfish" name="javax.json" rev="1.0.4" />
<dependency org="org.glassfish.jersey.containers" name="jersey-container-servlet" rev="2.23.2" />
</ivy:retrieve>
<war destfile="${war.file}" webxml="${resources.dir}/web.xml">
<fileset dir="${resources.dir}" excludes="web.xml"/>
<lib dir="${build.dir}/lib"/>
</war>
所以总而言之,虽然这个建议的答案可行,但我建议调查配置如何与外部 ivy 文件协同工作以管理您的依赖项。配置可能看起来具有挑战性,但它们也非常强大。
你的另一个问题是相关的。使用 ivy 的内联模式很方便,但不是使用 ivy 的最有效方式。对 resolve 任务的单个调用可用于确定项目的所有依赖项,并使用配置将它们划分为各种类路径或文件集等。
我在 build.xml
中有一个技巧,可以将所有依赖项下载到缓存中:
<target name="init" depends="init-ivy">
...
<ivy:cachepath
inline="true"
module="jersey-container-servlet"
organisation="org.glassfish.jersey.containers"
pathid="jersey.classpath"
revision="2.23.2"/>
<ivy:cachepath
inline="true"
module="javax.json"
organisation="org.glassfish"
pathid="json.classpath"
revision="1.0.4"/>
...
</target>
代码编译成功并创建了一个 war
文件。现在我需要编写一个任务来将应用程序部署到 tomcat。我需要将所有依赖项复制到应用程序的 WEB-INF/lib
。这是怎么做到的?也许有一种方法可以将依赖项的 JAR 包含到 WAR 文件中?我是 Java 开发的新手,请帮忙。
以下答案概述了使用 ivy file 的综合解决方案。
它回答了一个不同的问题("provided" 依赖项),但你最终会遇到这个问题,因为并不是你在构建中使用的所有 jar 都需要随你的应用程序一起提供(因为它们已经存在于 tomcat).
尝试将此答案应用于您的问题并不简单,因为您正在以内联模式(无 ivy 文件)解析依赖项。首先,我建议将您的依赖项组合到一个路径中,而不是围绕每个依赖项创建路径:
<ivy:cachepath pathid="compile.classpath">
<dependency org="org.glassfish" name="javax.json" rev="1.0.4" />
<dependency org="org.glassfish.jersey.containers" name="jersey-container-servlet" rev="2.23.2" />
</ivy:cachepath>
其次(并回答你的问题),它是备用常春藤 retrieve task that's used to place ivy files on the file system. It too can support an inline resolution 如下:
<ivy:retrieve pattern="${build.dir}/lib/[artifact].[ext]">
<dependency org="org.glassfish" name="javax.json" rev="1.0.4" />
<dependency org="org.glassfish.jersey.containers" name="jersey-container-servlet" rev="2.23.2" />
</ivy:retrieve>
<war destfile="${war.file}" webxml="${resources.dir}/web.xml">
<fileset dir="${resources.dir}" excludes="web.xml"/>
<lib dir="${build.dir}/lib"/>
</war>
所以总而言之,虽然这个建议的答案可行,但我建议调查配置如何与外部 ivy 文件协同工作以管理您的依赖项。配置可能看起来具有挑战性,但它们也非常强大。
你的另一个问题是相关的。使用 ivy 的内联模式很方便,但不是使用 ivy 的最有效方式。对 resolve 任务的单个调用可用于确定项目的所有依赖项,并使用配置将它们划分为各种类路径或文件集等。