简体   繁体   English

如何在我的build.xml中将所有依赖项部署到tomcat

[英]how to deploy all dependencies to tomcat in my build.xml

I have a tack in build.xml that downloads all dependencies to the cache: 我在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>

The code compiles successfully and a war file is created. 代码成功编译并创建了war文件。 Now I need write a task that would deploy the app to tomcat. 现在,我需要编写一个任务,将应用程序部署到tomcat。 I need to copy all dependencies to the app's WEB-INF/lib . 我需要将所有依赖项复制到应用程序的WEB-INF/lib How is this done? 怎么做? Maybe there is a way to include the dependencies' JARs to the WAR file? 也许有一种方法可以将依赖项的JAR包含到WAR文件中? I am new to Java development, please help. 我是Java开发的新手,请帮忙。

The following answer outlines the comprehensive solution using an ivy file . 以下答案概述了使用ivy文件的全面解决方案。

It answers a different question ("provided" dependencies) but one you will eventually face because not all the jars you use in your build will need to shipped with your application (because they already exist on tomcat). 它回答了一个不同的问题(“提供的”依赖项),但是您最终将面临一个问题,因为并不是您在构建中使用的所有jar都需要随应用程序一起提供(因为它们已经存在于tomcat上)。

Attempting to apply this answer to your question is not straightforward because you're resolving your dependencies in inline mode (No ivy file). 尝试将这个答案应用于您的问题并非易事,因为您正在以内联模式(没有ivy文件)解决依赖关系。 Firstly I'd recommend combining your dependencies into a single path, rather than creating paths around each dependency: 首先,我建议将您的依赖项合并到一个路径中,而不是围绕每个依赖项创建路径:

<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>

Secondly (and to answer your question), it's the alternate ivy retrieve task that's used to place ivy files on the file system. 其次(并回答您的问题),它是备用的常春藤检索任务,用于将常春藤文件放置在文件系统上。 It too can support an inline resolution as follows: 它也可以支持以下内联解析

<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>

So in conclusion, while this suggested answer will work, I would recommend investigating how configurations work in concert with an external ivy file to manage your dependencies. 因此,总而言之,尽管此建议的答案将起作用,但我建议调查配置如何与外部常春藤文件协同工作以管理依赖项。 Configurations may appear challenging, but they're also very powerful. 配置可能看起来很有挑战性,但功能也非常强大。


Your other question is related. 您的其他问题有关。 Using ivy's inline mode is convenient but not the most efficient way to use ivy. 使用常春藤的内联模式很方便,但不是使用常春藤的最有效方法。 A single call to the resolve task can be used to determine all a project's dependencies and using configurations to partition these up into various classpath or filesets, etc. 单个调用resolve任务可用于确定所有项目的依赖项,并使用配置将其划分为各种类路径或文件集等。

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

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