Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

build.xml Questions

Status
Not open for further replies.

jem122974

Programmer
Nov 1, 2001
114
0
0
US
I'm trying to create a jar file from an build.xml that needs to include one class file and one other jar file.

1) How do I specify the class file that has the main?
2) How do I include this additional jar file?

Thanks,
Jon Mitchell
East Jordan Iron Works
 
I’m no expert on ant, and I’m not sure that I get all that you mean. BUT..

Do you mean the class is to be the starting class when the jar file is executed OR do you mean include the class file with the other class files in the jar all to be included in this build??

Below is one of my tipical build.xml jar tasks….

<!--
jar. again depends on compile so compile is run first.
destfile and basedir are pretty straightforward.
the manifest attribute can be set 'inline' if you like and just point it at a file.
but I prefer to generate it this way..
-->

Code:
    <target depends="compile" name="jar">
        <jar basedir="${build}/classes" destfile="${build}/theProject.jar">
             <manifest>
                <attribute name="Main-Class" value="src.example"/>
<!--
in my build directory at the moment I'm only using 3 librarys so I didn't
bother creating a lib folder in the build folder. instead the jars are in the
build directory itself along with my " theProject.jar.jar"

-->
Code:
                <attribute name="Class-Path" value="src.JTable_Project.jar"/> 
            </manifest>
        </jar>
    </target>

This will create a jar with the following structure.


Code:
                   --> META-INF --> MANIFEST
theProject.jar
	           --> src --> yourClasses……
NOTE:
the main ‘starting’ class is set above using the <manifest> -> attribute name="Main-Class


With ant you need to be prepared to play around a bit, have you read the Ant docs (See Core Tasks).

Have fun regards Phil

Just for referance, heres the compile task:

Code:
    <target depends="init" name="compile">
      <javac destdir="${build}/classes" srcdir="${src}">    
        <classpath>
              <pathelement location="${lib}"/>
                  <fileset dir="${lib}">
                    <include name="**/*.jar"/> 
                  </fileset>
          </classpath>
      </javac>
    </target>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top