1

How does one go about creating two Jars from one project source folder? Is that possible, or must I create another project? My project uses Ant right now to generate one Jar. For example, say I want to split up the class files like this:

Jar 1:
    com.myproject.Foo
    com.myproject.Bar
Jar 2:
    com.myproject.FooBar
    com.myproject.BarFoo
    com.myproject.FooBarFoo
    ...
Jonah
  • 9,991
  • 5
  • 45
  • 79

1 Answers1

1

See http://ant.apache.org/manual/Tasks/jar.html. You just have to use filesets or includes/excludes inside your jar task to include only the files you want in each jar:

<target name="makeJars">
    <jar destfile="jar1.jar" 
         basedir="classes" 
         includes="com/myproject/Foo.class, com/myproject/Bar.class"/>

    <jar destfile="jar2.jar" 
         basedir="classes" 
         includes="com/myproject/FooBar.class, com/myproject/BarFoo.class, com/myproject/FooBarFoo.class" />
</target>
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • Instead of explicitly listing each class, can I just include a directory/package? – Jonah Apr 28 '11 at 17:11
  • 1
    Of course. Read the documentation for the includes attribute. It says: "comma- or space-separated list of **patterns** of files that must be included". And here's what the ant documentation says about patterns: http://ant.apache.org/manual/dirtasks.html#patterns. Reading the documentation is the right way to learn about products and technologies. Do it. – JB Nizet Apr 29 '11 at 07:10