ant compiling/jarring, with source folders

J

Joshua Jones

The source structure looks like this:

-src
|--a
| |--com
| | |--blah
| | |--MyObj.java
|--b
|--com
|--blah
|--OtherObj.java

I can use the <javac> ant task to compile with a base directory of
"src", and all files will be compiled in src/a/com/blah and
src/b/com/blah.

I want to jar my class files up, but I want the base directory to be
"com", not "src", so that my jar file contains no references to source
folders "a" and "b", like so:

/com/blah/MyObj.class (originally with a parent folder of "a")
/com/blah/OtherObj.class (originally with a parent folder of "b")

However, the <jar> task requires a single base directory, and if I use
"src", then my jar file will look like:

/a/com/blah/MyObj.class
/b/com/blah/OtherObj.class

Is there some way to accomplish what I want without having to <copy>
all generated class files over to another directory and then using
<jar>?
 
Z

zoopy

The source structure looks like this:

-src
|--a
| |--com
| | |--blah
| | |--MyObj.java
|--b
|--com
|--blah
|--OtherObj.java

I can use the <javac> ant task to compile with a base directory of
"src", and all files will be compiled in src/a/com/blah and
src/b/com/blah.

I want to jar my class files up, but I want the base directory to be
"com", not "src", so that my jar file contains no references to source
folders "a" and "b", like so:

/com/blah/MyObj.class (originally with a parent folder of "a")
/com/blah/OtherObj.class (originally with a parent folder of "b")

However, the <jar> task requires a single base directory, and if I use
"src", then my jar file will look like:

/a/com/blah/MyObj.class
/b/com/blah/OtherObj.class

Is there some way to accomplish what I want without having to <copy>
all generated class files over to another directory and then using
<jar>?

Don't use 'basedir' attribute but use nested <fileset> elements

<jar destfile="whatever.jar">
<fileset dir="src/a" />
<fileset dir="src/b" />
</jar>

Read your Ant manual for the 'includes' and 'excludes' attributes of <fileset>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top