VM arguments in manifest?

  • Thread starter Daniel Schneller
  • Start date
D

Daniel Schneller

Hi!

I have to build an application into a self-running jar file (let the
users double-click it on Windows). No problem there. However the
application requires a system property to be set. Is it possible to add
the definition of this property to the manifest?

Example:
java -Djava.security.auth.login.config==theconfig.config -jar myapp.jar

I would like to get rid of the -D.... part by somehow specifying the
default in the manifest, because that would require me to have a
separate launcher. The config file can easily be packed into the jar
file, be placed next to it or whereever, as long as I don't have to
specify it directly.

Any ideas? Perhaps I am just missing something plain stupid, but I
really seem to be stuck here.

Thanks in advance,
Daniel
 
J

Jeffrey Palm

Daniel said:
Hi!

I have to build an application into a self-running jar file (let the
users double-click it on Windows). No problem there. However the
application requires a system property to be set. Is it possible to add
the definition of this property to the manifest?

Example:
java -Djava.security.auth.login.config==theconfig.config -jar myapp.jar

I would like to get rid of the -D.... part by somehow specifying the
default in the manifest, because that would require me to have a
separate launcher. The config file can easily be packed into the jar
file, be placed next to it or whereever, as long as I don't have to
specify it directly.

Any ideas? Perhaps I am just missing something plain stupid, but I
really seem to be stuck here.

Thanks in advance,
Daniel

Try:

static {
System.setProperty("java.security.auth.login.config",
theconfig.config);
}

in the main class.

Jeff
 
D

Daniel Schneller

Try:
static {
System.setProperty("java.security.auth.login.config",
theconfig.config);
}

in the main class.

Thank you! I will try that.
However I would prefer not to change the application source. I would
like to deploy to different target environments which require different
configs.
Is there a way to do this without modifying the code? E. g. in the Manifest?

Daniel
 
M

Michiel Konstapel

Thank you! I will try that.
However I would prefer not to change the application source. I would like
to deploy to different target environments which require different
configs.
Is there a way to do this without modifying the code? E. g. in the
Manifest?

Daniel

Not directly but you can package a properties file in the JAR, read that at
startup and put those settings into the system properties. Then you can
just deploy JARs with different property files.
HTH,
Michiel
 
P

P.Hill

Michiel said:
[...] but you can package a properties file in the JAR, read that
at startup and put those settings into the system properties. Then you
can just deploy JARs with different property files.

What I would do in that case is
create a application properties list which has as it default list
the system properties.

http://java.sun.com/j2se/1.4.2/docs/api/java/util/Properties.html#Properties(java.util.Properties)
So instead of System.setProperties you are always doing something like
MyApplication.setProperties( ... );

and MyApplication has in it (or inherits)

this.properties = new Properties( System.getProperties() );

This will allow the simple loading of all properties from a
file with 1 statement

this.properties.load( this.iniFileName );

One implementation of such a routine is:

public void readIniFile(String iniFilePath) throws FileNotFoundException,

IOException {
if ( null == iniFilePath ) {
iniFilePath = INI_FILE;
}
URL url = Thread.currentThread().getContextClassLoader().getResource(
iniFilePath );
if ( null == url ) {
throw new FileNotFoundException( iniFilePath );
}
String fullpath = url.getFile().toString();

InputStream inputStream = url.openStream();
this.iniFile = url.getPath();

props = new Properties();
props.load( inputStream );
}

I have that in an Application baseclass I have usd for various simple
application which use there own INI file.

HTH,
-Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top