我无法通过终端与Ant编译源代码,因为尽管我发出"蚂蚁解析或蚂蚁检索",依赖性似乎没有正确解决?
我的build.xml和ivy.xml下面
build . xml
<!-- ANT HOME ENVIRONMENT VARIABLE -->
<property name="ant.home" value="${env.ANT_HOME}" />
<!-- IVY HOME DIRECTORY -->
<property name="ivy.home" value="${ant.home}" />
<!-- IVY2 JAR DIRECTORY (REPOSITORY) -->
<property name="ivy.default.ivy.user.dir" value="${user.home}/.ivy2"/>
<!-- DOWNLOAD IVY -->
<target name="setup" description="Install ivy">
<mkdir dir="${user.home}/.ivy2" />
<get dest="${ivy.home}/lib/ivy.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.3.0/ivy-2.3.0.jar"/>
</target>
<!-- RESOLVE CLASSPATHS -->
<target name="resolve" description="Use ivy to resolve classpaths">
<ivy:resolve file="ivy.xml" />
<ivy:report todir='target/ivy-reports' graph='false' xml='false'/>
<ivy:cachepath pathid="ivy.path" conf="compile" />
</target>
<!-- RETRIEVE DEPENDANCIES AFTER RESOLVING-->
<target name="retrieve" depends="resolve" description="Use ivy to retrieve dependencies">
<ivy:retrieve sync="true" type="jar" />
</target>
<!-- COMPILE PROJECT -->
<target name="compile" depends="clean, retrieve">
<!-- Create build directory -->
<mkdir dir="target/${ant.project.name}" />
<!-- Compile source code -->
<javac includeantruntime="false" srcdir="src" debug="true" destdir="target/${ant.project.name}" >
<classpath>
<path refid="ivy.path" />
</classpath>
</javac>
</target>
<!-- CLEAN TARGET DIRECTORY -->
<target name="clean">
<delete dir="target/orderlycalls" />
<delete dir="target/classes" />
<delete dir="target/ivy-reports" />
</target>
<!-- CLEAN TARGET AND IVY CATCHE -->
<target name="clean-all" depends="clean" description="Additionally purge ivy cache">
<ivy:cleancache/>
</target>
中
<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
<configurations>
<conf name="default" visibility="public" description="The single built artifact. Nothing else"/>
<conf name="compile" visibility="public" description="The master module and transitive dependencies"/>
<conf name="provided" visibility="public" description="Needed for compile. Will be provided outside or war"/>
<conf name="runtime" visibility="public" description="Not required for compile, but for runtime" extends="compile"/>
<conf name="default" visibility="public" description="The default configuration" extends="runtime"/>
<conf name="test" visibility="private" description="Required for testing" extends="runtime"/>
</configurations>
<dependencies>
<dependency org="net.sf.trove4j" name="trove4j" rev="3.0.3" conf="provided"/>
<dependency org="org.apache.tomcat.embed" name="tomcat-embed-core" rev="7.0.53" conf="provided"/>
</dependencies>
</ivy-module>
当我运行'ant编译'时,编译蚂蚁抱怨它找不到'Servlet上下文',这是tomcat.jar或'TObject'的一部分,'THashMap'是trove.jar的一部分,尽管我正在检索/解决build.xml中的jar。
我注意到的另一件事是,在我的.ivy2/cache//中没有实际的jar文件。仅限xml文件
你知道我做错了什么或者根本没做什么吗?
谢谢
您已经使用cachepath任务创建了一个Ant路径,使用与"compile"配置相关联的依赖项。
<ivy:cachepath pathid="ivy.path" conf="compile" />
你的问题在于你的ivy文件,在那里你没有指定任何映射到"编译"配置的依赖关系。这就解释了为什么javac任务看不到任何jar。
<configurations>
...
<conf name="compile" .../>
<conf name="provided" .../>
...
</configurations>
<dependencies>
<dependency ... conf="provided"/>
<dependency ... conf="provided"/>
</dependencies>
我建议为您的每个配置创建一个显式映射,例如:
<!-- Compile dependencies -->
<dependency org="net.sf.trove4j" name="trove4j" rev="3.0.3" conf="compile->default"/>
<!-- provided dependencies -->
<dependency org="org.apache.tomcat.embed" name="tomcat-embed-core" rev="7.0.53" conf="provided->master"/>
您需要的唯一映射是到以下远程配置:
- default远程jar及其传递依赖
- master Remote jar only
有关ivy如何解释远程maven模块的更多信息,请阅读以下内容:
- maven作用域如何被ivy 映射到ivy配置