What I want to do with Apache Ant:

  1. Create 1 jar file
  2. Inside it is such a structure

    / lib / <- add all libraries here
    / META-INF / <- here indicate the Main-Class
    / com / ... <- compiled classes
    / here configs files

Is it possible to do so, if so, how to put all the libraries that are in different folders in the folder lib + when calling

java -jar name.jar 

These libraries provided this jar to the classpath. Thank you.

He did this, but he puts all the classes in the jar-nick's root (along with the folders)

 <jar destfile="${build.dir}/out/name.jar"> <fileset dir="${classes.dir}"> <include name="**/*.class"/> </fileset> <zipfileset dir="${lib.dir}"> <include name="**/*.jar"/> </zipfileset> <manifest> <attribute name="Main-Class" value="mypackage.myClass" /> </manifest> </jar> 

    2 answers 2

    I understand you have two questions:

    1. how to put the jar-nicks in the lib / folder inside another jar. This is achieved using the prefix attribute of the zipfileset
    2. How to make it so that when you start java -jar name.jar, what got into the lib is in the classpath. This can be achieved with the help of one jar , if you do not want to mess around, and then the first part of the question disappears by itself, or manually with the help of the Jar class loader

      It seems like it can not be done directly. You will have to specially prepare a directory in the build, which accurately describes the contents of jar .. fill it with mkdir, copy, etc, and then pack it with jar with one blow.