Include JAR file in ant compilation

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

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

How to edit the file build.xmlfor the second application to include the JAR file that I created? When I compile my project, functions from JAR files are not allowed:

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

EDIT:
When I add the task javacto mine build.xml, compilation fails because no other packages were 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 source packages not found after including the JAR file?

+3
source share
3 answers

. , , , .. , , .

:

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

. javac.

+5

JAR .

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

. .

0

classpath classpathref javac classpath, javac ant ..

: Java .

0

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


All Articles