Create a jar file from the source folder using build.xml

I have an API that has the following structure:

The folder has a source folder and a build.xml file. How can I create a jar of this?

+6
source share
3 answers

If the build.xml file does not yet have a target that creates the jar file, you can read the ant jar command here:

However, there is probably a good chance the build file is already doing this for you.

You can start the build script by typing ant when you are in the directory that contains the build.xml file (after unpacking the banner).

Just for fun, here is an example of a simple ant target that compiles some code and creates a jar.

This goal will compile every .java file in any folder with report names.

As you can see, most values ​​use variables defined elsewhere in the script, but hopefully you get this idea ...

<target name="create-funky-jar" depends="some-other-funky-targets"> <javac srcdir="${src.dir}" includes="**/reports/*.java" destdir="${build.classes.dir}" deprecation="${javac.deprecation}" source="${javac.source}" target="${javac.target}" includeantruntime="false"> <classpath> <path path="${javac.classpath}:${j2ee.platform.classpath}"/> </classpath> </javac> <jar destfile="${dist.dir}/SomeFunkyJar.jar" basedir="${build.classes.dir}" includes="**/reports/*.class"/> </target> 

The above was created only by modifying the assembly of the script generated by NetBeans.

You can run the above object by adding it to the build.xml file and entering the following at the command line:

 ant create-funky-jar 

Note. You will need to define all the variables in order for it to actually work.

+9
source

build.xml is the file used by ant, and it may contain the ant procedure that must be followed to create the appropriate file (e.g. jar ).

I would recommend reading something like this manual (chapters called "Installation and Launch"). Another option would be to use Netbeans, since it already has ant, and it has options for creating a project from an existing build.xml .

0
source

In the directory where the build.xml file is located, type

 ant -p 

You might need to install ant first.

If there is a goal to create a jar, select it, for example

 ant jar 
0
source

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


All Articles