Ant: add one compiled class file to java class?

In Ant, if I have a single compiled CLASS file located somewhere inside my project (say, in gen/stragglers/SomePOJO.class ), there is a way to specifically add this class file to my <javac> class path when I have the following:

 <javac includeantruntime="false" srcdir="src/main/java" destdir="gen/bin/main"> <classpath refid="main.compile.path"/> </javac> 

If not, why? If so, how? Thanks in advance!

+4
source share
2 answers

Builld path referencing your class file:

 <path id="javac.classpath"> <pathelement location="./gen/stragglers/SomePOJO.class"/> </path> 

Then use it in your javac task:

 <javac srcdir="./src/main/java" destdir="./gen/bin/main"> <classpath refid="javac.classpath"/> </javac> 
+4
source

You cannot add a single class file as such, you add a directory to the class path, and the compiler will search for classes in this directory by relative paths obtained from their package structure. This, to my knowledge, is not negotiable. The directory structure must match the package structure.

So, for example, if the class defined in SomePOJO.class is stragglers.SomePOJO , you must add the gen directory to the classpath

 <javac includeantruntime="false" srcdir="src/main/java" destdir="gen/bin/main"> <classpath> <pathelement location="gen" /> <path refid="main.compile.path"/> </classpath> </javac> 

If the path to the .class file does not match the package declaration of the class, then you will have to move it to a temporary directory that matches the package structure, and then add this directory to the classpath.

+4
source

Source: https://habr.com/ru/post/1492315/


All Articles