简体   繁体   中英

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.

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.

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.

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. I just want to create a build.xml to run from the command line.

Thanks in advance.

No Ant cannot determine dependencies automatically. That's specifically one reason why projects like Maven and Ivy were introduced.

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. So your assumption is simply incorrect.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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