Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include JAR file in ant compilation

Tags:

java

jar

ant

I want to compile some .java files into a JAR. I would like to use this JAR file in another application.

Is this a good way to use functions from my first application in my second application? My goal is to not duplicate code.

How can I edit the build.xml file for the second application to include the JAR file I created? When I compile my project, functions from JAR files are not resolved :

[javac] C:\HelloWorld\src\com\example\helloworld\HelloWorld.java:7: 
        package TOOLS does not exist  
[javac] import TOOLS.Logs;

EDIT:
When I add the javac task in my build.xml, compilation fails because other packages are not found:

[javac] Compiling 1 source file
[javac] C:\HelloWorld\src\com\example\hellowolrd\HelloWorld.java:3: 
        package android.app does not exist
[javac] import android.app.Activity;
[javac]                   ^

Why are my original packages not found after I include the JAR file?

like image 703
TheFrancisOne Avatar asked Mar 19 '26 20:03

TheFrancisOne


1 Answers

Yes. It's good practice generally to subdivide functionality into libraries for reuse, ease-of-development etc. It'll speed development if they're separately built, and you can easily distribute functionality to successive projects.

You can reference your jar thus:

  <javac srcdir="${src}"
         destdir="${build}"
         classpath="xyz.jar"
         debug="on"
  />

See the javac documentation for more information.

like image 113
Brian Agnew Avatar answered Mar 22 '26 10:03

Brian Agnew