Setting a Classpath variable in a java standalone app


 I have a java app that I bundled up using Jar Bundler to produce a .app, double clickable java app. However, one of the libraries I am using in the app requires a certain environmental variable be set to run correctly.  Is there some way to have the bundle set it before starting the java app (Like perhaps something in the Info.plist).  
valcarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
You could try to set it in a shortcut command

java -Dsomevar=someval MyClass

and then access it inside the app
0
valcarAuthor Commented:
Tried that in the Info.plist in the VMOptions string. Did not work.
0
CEHJCommented:
I'm unfortunately not familiar with the Mac, but is this not OS X? If so, what shell do you get? Can you get a bash-like shell?
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

CEHJCommented:
Got to sign off now as very late here but try to run a shell script with something like the following in it:

export somevar=someval
java MyClass

and then you should be able to access somevar in the app
0
valcarAuthor Commented:
If I run the Java app from a command (bash) shell I can use

export var=value
java -jar my.jar My.Main
 
to run it succesfully.    
However, there is a tool called Jar Bundler that basically wraps a jar in a specialized folder called My.app that OS X treats as an application. Double clicking on the My.app starts the tool as if you typed java -jar.....  on a command line. However, I need some way to set the var=value as part of this process.

This answer will be very OS X specific I expect.
0
CEHJCommented:
Surely there's a way to invoke a shell script by double-clicking an icon? Why not do that?
0
valcarAuthor Commented:
Because then the application would have to install an entire folder (the double clickable shell script, the jar and supporting files) rather then have it all contained in this one App/Folder.   The beauty of this system is there are no files the user can delete by accident, move to the wrong place etc.  
0
objectsCommented:
Jar Bundler allows you to specify properties to be used when you doing the packaging, see the Properties tab.

0
valcarAuthor Commented:
Sadly those properties are not loaded as enviornmental variables as far as I can tell (I tried it). The libraries I am using require the env var be set.
0
objectsCommented:
sorry misunderstood, why can't you change the code to use System properties.
Using env vars is not that cross platform friendly.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.