aspose file tools*
The moose likes Java in General and the fly likes Jar files, Script Engines, File associations, OH MY! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Jar files, Script Engines, File associations, OH MY!" Watch "Jar files, Script Engines, File associations, OH MY!" New topic
Author

Jar files, Script Engines, File associations, OH MY!

Rooks Forgenal
Ranch Hand

Joined: Jun 05, 2009
Posts: 82
First, may I say hello to you all. I am glad you have chosen to read this post in an attempt to help.

My first problem lies with, well with a fundamental lack of understanding on how Jars are built or even 'what' jars are. All I know is that I select 'Run' in Netbeans menu and choose 'Build Main Project' and *poof*, a jar appears that I will call the "Program Jar" from here on. I would like to be able to send this Program Jar to a friend to show him my progressing skills in java. However, when this Program Jar is run where it is created, it runs great but, when it is moved to any other location, it fails to run correctly.

I realize I have been a bit vague on what is actually happening so let me break it down. I am reading a file in to my program using the

I am aware that this file is Ruby. That is on purpose. I am later reading this file and using the Ruby methods through a script engine manager.

The script engine manager needs two things, first; it needs the jruby-engine.jar and second; it needs the jruby-complete-1.3.1.jar. When I make this program Jar and run it in the project, it seems to have access to the two jruby jars and works great. When I move the Program Jar to a new location, it loses access to these jars and fails to run the jruby. The ScriptEngineManager in fact makes a null object named factory.


Ok, that is the problem, here is my question; How do I get my Program Jar to access and use both the jruby-engine.jar and jruby-complete-1.3.1.jar?

Thank you for your consideration,

Brightmatter
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38788
    
  23
Have a look at the documentation for the java.exe and javac.exe tools. Note one of those says "windows" but I don't think that matters for your purposes. Find the options about classpath for both tools. What you need to do is to add the .jar files to your classpath. You can do this at the command line when you compile and execute your .jar files.

You can also hack into your .jar file and edit its manifest file. You can add a line about classpath in the manifest file. Can't remember exactly how to do it, but look in the Java™ Tutorials and the 2nd section tells you about manifest files.

There is a 3rd "Campbell's Cheat" technique. I won't tell you how it works. I won't tell you to unzip all the other .jars. I won't tell you to put them inside your own folder structure. I won't tell you to create a new .jar.

I also won't tell you that you can't add .jars inside .jars (at least I don't think so), but you can unzip the files and add them to your .jar when they are unzipped.
Rooks Forgenal
Ranch Hand

Joined: Jun 05, 2009
Posts: 82
Well, I feel a bit foolish. I was not taking the "lib" directory with me when I moved the Program Jar. The Jar assumes that it will be in the same directory as itself and so when it was missing, it took offense.

Egg on face,

Brightmatter
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jar files, Script Engines, File associations, OH MY!