0

I have a jar file that needs to be executed and a library path that needs to be set before execution (library path is very important):

// works but without library path being set
start bin/myJar.jar

// should work but doesn't because OS path knows no java paths
// error message like: "java" could not be found
start java -Djava.library.path=bin\native -jar bin\myJar.jar

I think Oracle does very bad job on installation of their products because there is always manual operation necessary. I can't expect of my users to set the path variable by themselves. So is there a way to update the path variable via batch (temporary just for execution of this one jar would be best)?

I'm also using ant builds to generate jars. All settings I COULD do are these:

// ...
<manifest>
    <attribute name="Class-Path" value="another.jar another2.jar " />
    <attribute name="Main-Class" value="myPackage.MyClass" />
</manifest>
// ...

Is THERE a way to set library path ?

Bitterblue
  • 13,162
  • 17
  • 86
  • 124

2 Answers2

0

You can have all needed jars in the same folder. Then by default claspath is set to current directory.

Other option is to have your application installer which will copy jar files so Java can find it in default location: jre/lib/ext

Other option is to have your appliaction packed as zip archive and ask user to extract it. There should be starter script included for each operating system that you support. This way you can include in calsspath native jars dependant on OS

Aleksander Gralak
  • 1,509
  • 10
  • 26
0

As you've speculated the best approach is to create an executable jar, by specifying both the main class and class path in the jar's manifest.

See:

Using the manifestclasspath task means you can ship the jar and it's dependent libraries together. You batch script can then be a simple call as follows:

start java -jar myjar.jar
Community
  • 1
  • 1
Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185