Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Setting a Classpath variable in a java standalone app

Posted on 2004-11-04
12
Medium Priority
?
208 Views
Last Modified: 2013-12-26

 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).  
0
Comment
Question by:valcar
  • 4
  • 4
  • 2
10 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 12500348
You could try to set it in a shortcut command

java -Dsomevar=someval MyClass

and then access it inside the app
0
 

Author Comment

by:valcar
ID: 12500398
Tried that in the Info.plist in the VMOptions string. Did not work.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12500418
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:CEHJ
ID: 12500452
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
 

Author Comment

by:valcar
ID: 12500460
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 12500478
Surely there's a way to invoke a shell script by double-clicking an icon? Why not do that?
0
 

Author Comment

by:valcar
ID: 12500520
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
 
LVL 92

Expert Comment

by:objects
ID: 12500891
Jar Bundler allows you to specify properties to be used when you doing the packaging, see the Properties tab.

0
 

Author Comment

by:valcar
ID: 12501687
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
 
LVL 92

Accepted Solution

by:
objects earned 1000 total points
ID: 12501717
sorry misunderstood, why can't you change the code to use System properties.
Using env vars is not that cross platform friendly.
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Integration Management Part 2

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question