简体   繁体   English

Ant在构建jar文件时可以确定依赖性

[英]Can Ant determine dependencies while building jar file

I want to be able to use Ant to build a jar file based on a single class within a larger Java project and have it automatically determine dependencies. 我希望能够使用Ant在较大的Java项目中基于单个类构建jar文件,并使其自动确定依赖关系。

I can happily create an Ant build.xml file to create a jar for the project which contains all classes, though this contains many things not required in the jar. 我可以很高兴地创建一个Ant build.xml文件来为包含所有类的项目创建一个jar,尽管其中包含jar中不需要的许多东西。

When I include just a single source file, ie: 当我仅包含一个源文件时,即:

<patternset id="source.pattern"> <include name="MyProject/src/java/com/myproject/cow.java" /> </patternset>

then build the jar I get the obvious complaints about cannot find symbol (regarding objects within the project that are used in cow.java ), which indicates it is ONLY including the file I specified. 然后构建jar,我收到明显的抱怨: cannot find symbol (关于cow.java中使用的项目中的cow.java ),这表明它仅包含我指定的文件。

The fact that it can detect the missing symbols / classes / objects suggests it is capable of doing what I require. 它可以检测到丢失的符号/类/对象,这一事实表明它能够满足我的要求。

I don't want it to build from Eclipse. 我不希望它从Eclipse构建。 I just want to create a build.xml to run from the command line. 我只想创建一个build.xml从命令行运行。

Thanks in advance. 提前致谢。

No Ant cannot determine dependencies automatically. 没有任何Ant不能自动确定依赖关系。 That's specifically one reason why projects like Maven and Ivy were introduced. 这就是为什么引入像Maven和Ivy这样的项目的原因之一。

The fact that it can detect the missing symbols / classes / objects suggests it is capable of doing what I require. 它可以检测到丢失的符号/类/对象,这一事实表明它能够满足我的要求。

It's not Ant that's detecting the missing classes, it's the underlying Java compiler (typically the javac in the JDK) that's doing so. 检测缺失类的不是Ant,而是底层Java编译器(通常是JDK中的javac )正在执行此操作。 So your assumption is simply incorrect. 因此,您的假设完全是错误的。

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

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