• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

urgent help please (creating jar file using ant)

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am able to create jar file with all class files but I want to include
class files and java files with corresponding directory structure in the jar file.
I have one folder structure like
c:/src/src1
Now src contains some java files and src1 contains some other files.
What changes i need to do in the following code to include java files
also in the jar file.
<project name="MyProject" default="dist" basedir=".">
<description>
simple example build file
</description>
<!-- set global properties for this build -->
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
<target name="init">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}"/>
</target>
<target name="compile" depends="init" description="compile the source " >
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}" />
</target>
<target name="dist" depends="compile" description="generate the distribution" >
<!-- Create the distribution directory -->
<mkdir dir="${dist}/lib"/>
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar" basedir="${build}" />
</target>
<target name="clean" depends="dist" description="clean up" >
<!-- Delete the ${build} directory trees -->
<delete dir="${build}"/>
</target>
</project>

Any help how to add class files also to jar file.
Thanks,
Suchi.
 
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<jar destfile="${dist}/lib/app.jar"
basedir="${build}/classes"
includes="mypackage/test/**"
excludes="**/Test.class"
/>
This is the sample from Ant doc. Maybe try using attribute
includes="**/*.java"
It should pick up all the java files from basedir down.
 
suchitra gowda
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
The problem is my base directory is c:\ and if i say
includes="**/*.java" it picks from all directories. But I want to pick up those class files from 2 or 3 folders not from all the folders.
C drive has many folders and each folder contains lot files.
I have one more question.
Why is my delete is not working. The directory is not deleting. Even if print some message using under tag
<target name="clean" depends="dist" description="clean up" > like
<echo message="Hello" /> this message is also not printing.
Which means control is not entering into this tag.
Thanks,
suchi.
 
Tony Yan
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems to me that you have some hidden problems. You can start the Ant with -verbose to see if things are doing what you intend to. Post the dumps if you want here.
 
suchitra gowda
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am not clear what is mean by -verbose.
I comiled my ant script using ant -v -buildfile test.xml then it is displaying all the stuff except the message in the clean .
I added the following code before compile.
<target name="clean" description="Delete all old files" >
<echo message="Deleting all old class files" />
<delete includeEmptyDirs="true" >
<fileSet dir="" >
<patternSet refid="class.files" />
</fileSet>
</delete>
</target>
I can not see the echo message in the logs which means that this target tag is not executed.
Any help please how I have to solve this problem.
Thanks,
suchi.
 
suchitra gowda
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
If i try to delete the directory after jar file creation like
<target name="dist" depends="compile" >
<jar jarfile="${dist}/lib/MyProject.jar" basedir="${build}" />
<delete dir="${build}"/>
</target>
now the directory deleted successfully.
If i use that delete tag in different target then the directory is not deleted.
for ex:
<target name="clean" description="clean up" >
<delete dir="${build}"/>
</target>
What is the diff between these and why is not working ...
Any help on this please.
Thanks,
suchi.
 
Tony Yan
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry. I didn't look carefully. The depends="dist" will not work since your project default target is "dist", so the Ant will just finish everything that dist is depending on recursively ONLY. If any task is NOT in the dependence tree of "dist", it is not to be executed.
-v and -verbose are the same, I think.
Hope it helps.
 
suchitra gowda
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tony,
Thanks for your quick response.
I got it . What ever you said is correct ..
Thanks,
Suchi.
 
suchitra gowda
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tony,
I have one question regarding class path.
Here is the code i am using:
<!-- Tool directories as defined by the environment variables -->
<property environment="env"/>
<property name="classpath" value="${env.path}"/>
<!-- Classpath to compile our EJBs -->
<path id="server.classpath">
<pathelement location="${classpath}" />
</path>
<target name="compile" >
<javac srcdir="." classpathref="server.classpath" >
<patternset refid="source.files" />
</javac>
</target>
I am unable to compile my java files because of class path problem.
I tested by setting classpath also in environment variables.
Any help on class path .
thanks,
suchi.
 
Tony Yan
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can add something like this
<echo message="${classpath}"/>
to see if you are getting the right path from env.path. Looks okay to me as far as the buildfile goes. However, make sure if you are running on UNIX system, the path should be case-sensitive. Thus, env.path != env.PATH.
BTW, shouldn't you use env.CLASSPATH instead of env.PATH?
 
suchitra gowda
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tony,
Thanks for your response.
I got solution bu using path and pathelement tags like
<path id="fuclasspath">
<pathelement location="\common.jar" />
<pathelement location="\j2ee.jar" />
</path>
 
Tony Yan
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great! I'd recommend the same that you set CP inside each javac since in that way, you will have a clean CP to use for that task. Introducing CLASSPATH from Ant Env can potentially cause some problems for CP, as we know it.
 
Uh oh, we're definitely being carded. Here, show him this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic