【发布时间】:2021-03-24 23:45:41
【问题描述】:
我已经阅读了一些文章,但我无法理解如何为依赖项设置 Ivy 文件。我正在处理的项目很旧,我不太了解,我生成了这一半 - 一半编辑过的 build.xml 文件,它与 Eclipse 编译器一起工作。这是我第一次处理构建配置,我想将依赖项移动到 ivysettings.xml 文件并改进可以改进的地方。我的目标是创建一个部署在 Tomcat 中的战争。
最好的方法是什么?
build.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="build" name="Teamwork"
xmlns:ivy="antlib:org.apache.ivy.ant">
<property environment="env"/>
<property name="ECLIPSE_HOME" value="../../../../../Program Files/eclipse/"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.7"/>
<property name="source" value="1.7"/>
<path id="Web App Libraries.libraryclasspath">
<pathelement location="WebContent/WEB-INF/lib/Tidy.jar"/>
<pathelement location="WebContent/WEB-INF/lib/antlr-2.7.7.jar"/>
<pathelement location="WebContent/WEB-INF/lib/asm-attrs.jar"/>
<pathelement location="WebContent/WEB-INF/lib/asm.jar"/>
<pathelement location="WebContent/WEB-INF/lib/avro-1.5.1.jar"/>
<pathelement location="WebContent/WEB-INF/lib/aws-java-sdk-1.5.5.jar"/>
<pathelement location="WebContent/WEB-INF/lib/bsh-2.0b4.jar"/>
<pathelement location="WebContent/WEB-INF/lib/c3p0-0.9.2.1.jar"/>
<pathelement location="WebContent/WEB-INF/lib/commons-beanutils.jar"/>
[... other jars]
</path>
<path id="EAR Libraries.libraryclasspath"/>
<path id="Teamwork.classpath">
<pathelement location="bin"/>
<path refid="Web App Libraries.libraryclasspath"/>
<path refid="EAR Libraries.libraryclasspath"/>
</path>
<target name="init">
<mkdir dir="bin"/>
<copy includeemptydirs="false" todir="bin">
<fileset dir="src">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="bin"/>
</target>
<target depends="clean" name="cleanall"/>
<target depends="build-subprojects,build-project" name="build"/>
<target name="build-subprojects"/>
<target depends="init" name="build-project">
<echo message="${ant.project.name}: ${ant.file}"/>
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}">
<src path="src"/>
<classpath refid="Teamwork.classpath"/>
</javac>
</target>
<target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/>
<target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
<copy todir="${ant.library.dir}">
<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
</copy>
<unzip dest="${ant.library.dir}">
<patternset includes="jdtCompilerAdapter.jar"/>
<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
</unzip>
</target>
<target description="compile project with Eclipse compiler" name="build-eclipse-compiler">
<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
<antcall target="build"/>
</target>
</project>
【问题讨论】:
-
Ant 和 Ivy 过时了。如果您仍然努力的话,我建议您迁移到 Maven。
-
我看不出迁移到 Maven 项目的原因,只是因为“它更新了”,如果这有效的话。然而,在直接迁移到 Maven 之前集成 Ivy 将有助于该过程。 stackoverflow.com/questions/17237679/…
-
并不是说 Maven 比较新。它比 Ivy 更擅长管理依赖项。事实上,它已经相当老了。没有人再使用 Ant 或 Ivy。查看所有的开源 Java 项目。他们都使用 Maven 或 Gradle。蚂蚁消失了。
-
就我而言,现在不需要。可能会考虑未来的改进。现在,是没有目的的。谢谢你的建议。
标签: java eclipse build ant ivy