tags:

views:

424

answers:

2

I wonder if this is possible with ant and java:

I have a Java project which looks like this:

./
  build.xml
  src/
    com/
      example/
        {.java files here} 
  bin/
    com/
      example/
        {compiled .class files here} 
  lib/
    {3rd-party jar files here}
  dist/
    {jar file(s) here}

I know how to make a .jar file that contains the stuff in the bin/ directory, with the right manifest to make it run my main Java class.

What I would like to do, if possible, is to make a .jar file that:

  1. Java can execute ("java -jar myproject.jar")
  2. Someone else can unzip to create the project structure. (including all the subdirectories except for the "dist/" directory)

Is this possible? I can't seem to tell Java to use the bin/ subdirectory of the .jar file as the classpath, I may be screwing up the syntax somehow.

edit: Okay, it sounds like trying to make one object serve two (too many) purposes. I have abandoned this approach, instead creating a standard .jar file as the executable, and a .zip file with the source (the build.xml + the src and lib directories). That way there are 2 easy downloads, more than 1 file but not too bad.

+4  A: 

No, UrlClassLoader always tries to find classes based in the root, and a jar URL will always fetch entries based in the root of the jar file.

You could create a jar file which has binaries from the root, but source files under src etc. That wouldn't be too bad, assuming you really do just have com as the only "root" package.

Jon Skeet
A: 

You could put your project on a public SVN server, and just include instructions on how to check out the source - you'd also benefit from other people's check-ins and improvements (hopefully not vandalism).

JeeBee
I'm doing that anyway, I just want to make it more convenient for users.
Jason S