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:
- Java can execute (“java -jar myproject.jar”)
- 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.
No,
UrlClassLoaderalways 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
comas the only “root” package.