Different ways of bundling JARs

I thought I had messed up the classpath, but really it was just Eclipse sucking.

So I’ve got a folder of resources in my project, “data.” It has “images” “fonts” and “sounds” in it. So that I can read these files from the classpath, I right clicked on the data folder and told Eclipse to include it in the build path. Happy days, everything reads from the classpath correctly as if it were in a JAR.

But I find that after doing that when I export a JAR with eclipse it puts the images and sounds directories outside of the data folder. As in, in the top level, along with bin and src, we have data, sounds, and images. And yet, inside data there is the fonts folder.

Any ideas why this is being junky? If I remove the data folder from the build path every time I export a JAR it works. But otherwise, notsomuch.

Huh, that’s a strange problem. I haven’t had any issues like that myself, and I use some seriously nested directories at times. Of course, I’m also an avid ANT user now and haven’t used the built in jar exporter for a while.

Have you checked to make sure that they’re actually folders? (Check the file view as opposed to the Java view)

I don’t have folder problems with Eclipse. Ditto elias4444, I am using Ant to build my projects.

Maybe I should get with the times and use Ant. :stuck_out_tongue:

You should really use it to make JARs, it just works as expected :slight_smile: You can obviously use it in Eclipse. If you need a complete working example of use of ANT to make a JAR, create a certificate from your inputs, sign this JAR with this certificate, etc… look at the build.xml file that I use in the pre-beta version of TUER.

I don’t have problems with eclipse folders either. I am using Maven to build my projects (generate the jar and sign all dependencies, etc). The best thing is I can regenerate .classpath, .project and .settings with the pom.xml from Maven any time I want :D.

I’m not trying to compare Maven and Ant, I am only commenting as the others which tools I use and that I don’t have folder problems.

I believe the consensus is that you’ve just gone bat crazy, Demonpants ::slight_smile:

Bllrrrgglggbrbrg… :persecutioncomplex:

If it keeps happening then I will record it and put it on YouTube.

You put the contents of the data directory on the classpath. When it makes a JAR, it includes the contents of the data directory, not the data directory itself. I have a directory called “resources” in my projects that contains non-source code files that will go in the JAR. In your case you would have “reources/data/sounds/eg.wav”.

If you reference files in your code with “data/sounds/sound.wav”, then it can work in Eclipse by finding the file on the filesystem, since the app is run out of the project folder. It may even find it from the classpath if Eclipse puts the project folder on the classpath, but I don’t think it does.

Ant sucks. Stay away. Maven sucks too, even worse.

Never had a problem with Ant. You especially need it with team development.

Ant is useful and the de facto standard, but I hate having to edit build files. XML is an odd choice for a scripting language.

Maybe I’m just ignorant, who knows, but I never really get the need for build applications. I can’t stand waiting for javac to compile a huge project, why would I wait (much) longer than 1sec by using Ant?

I just write a trivial one-class-app for each project that puts all data in the correct zip/jar and looks up dependencies and whatnot.

What exactly am I missing out on?

Just because a tool can do a job, doesn’t make it a good tool. Ant doesn’t bring anything to team development, in fact usually makes things worse when people start copy/pasting large Ant files.

Perfect example of popularity having nothing to do with how good a tool is!

Absolutely nothing! I do similar, though for me it is a script. Less than 150 lines of script (including whitespace) and I can compile, JAR, sign, and create javadocs. The script is reusable across projects.

For kicks, I wrote a project to make writing my build scripts easier:
http://code.google.com/p/wildcard/
It is great for collecting paths to JAR/zip/copy/move/etc.

Sounds like javascript would be a nice fit… whoever thought XML was the ultimate solution should be taken out and tickled to death.

XML IS THE FUTURE!

I don’t get XML. Everyone loves it, when in reality it’s difficult to read and takes up more memory than it needs to. It’s also slower at parsing than many other methods (not like this will be your bottleneck though). And yet people seem to (or used to seem to) poop all over the place in a frothing frenzy like this guy. I almost always used space, tab, or comma delimited text files where every line is a different element. Easier to read and better too. Or I just write bytes to a file. That’s of course the best solution.

Anyway. I like the script idea. I’ll just write a handy sh file to do all this shit for me. I’ve already got one for signing all my JARs, I might as well take it to the next level.

I saw the episode :persecutioncomplex:

Don’t forget XML is great for: {0}, {1} and {2}.

XML stinks and the idea that you need a programing language to compile some other stuff in a different programing language is bizarre.

Look at the auto build tools. You run a tool that writes a script that is run to write make files --which then has make run on to finally run compiler and then a linker.

In java I can not use ANT and its reasonably easy to compile with a single command line. I only started to use ant when my building required the continuations asm3 task. Also i do use if for my public projects since it is a defacto tool.

But really Riven, if your not missing it, you don’t need it.

However I do use ant tasks in eclipse for all my jar packaging now, since its easier not to forget something.

I think the copying of multiple directories into one, to zip it, is retarded. My code simply grabs the files, determines the relative paths and streams it into the JAR, warning me for duplicate entries. No file copy, no cleanup, much faster. I don’t even use Java’s zip classes, because calling an executable that does it for you is at least an order of magnitude quicker.

Oh well, I guess people accept delays when they are used to it. Like MSIE8 makes you wait up to 5 seconds to open a new tab. You think, ‘well, it starts a whole new browser in that tab’, until you see that every other browser on the planet opens new tabs instantly.

I really couldn’t force myself to wait for javac, dir-copies and whatever ant does more.

You might sharing this class? I’m curious to see what you did.

Like I said, I’ll probably do it in unix script rather than in Java and just use the jar tool via command line, but I can see why doing it in Java would be nicer - much more flexible if you need to get complicated. Fortunately, I don’t. :slight_smile:

Did my post fix your Eclipse issues?

Here’s some sample script that uses my wildcard project linked above:

dir = "../target/projetname/jws/"
unpackedDir = dir + "unpacked/"
mkdir(unpackedDir)
packedDir = dir + "packed/"
mkdir(packedDir)

glob("deploy", "*.jnilib", "*.dylib").zip(dir + "natives-mac.jar")
glob("deploy", "*.dll").zip(dir + "natives-win32.jar")
glob("deploy", "*.so").zip(dir + "natives-linux.jar")
for (name : glob(dir, "*.jar").names) {
	print(name + ": signing...")
	system("jarsigner -keystore build/keystore -storepass password -keypass password " + dir + name + " alias")
	println("...done.")
	println()
}

glob("../target/slick", "slick.jar").copyTo(unpackedDir)
glob("../target/projectname", "projectname.jar").copyTo(unpackedDir)
glob("lib").copyTo(unpackedDir)
for (name : glob(unpackedDir, "*.jar").names) {
	print(name + ": normalizing...")
	system("pack200 -S-1 -O -E7 -mlatest " + packedDir + name + ".pack.gz " + unpackedDir + name)
	system("unpack200 -r " + packedDir + name + ".pack.gz " + unpackedDir + name)
	print(" signing...")
	system("jarsigner -keystore build/keystore -storepass password -keypass password " + dir + name + " alias")
	system("pack200 -S-1 -O -E7 -mlatest " + packedDir + name + ".pack.gz " + unpackedDir + name)
	writeText(`URI: packed/` + name + `.pack.gz
Content-Type: x-java-archive
Content-Encoding: pack200-gzip

URI: unpacked/` + name + `
Content-Type: x-java-archive`, dir + name + ".var")
	println("...packed.")
	println()
}