0

I have a dummy jar, whose only job is to display a simple jdialog and ask user to select required memory size from the combo provided.After selecting required maximum memory user clicks start button to run my main Jar.

I am using runtime.getRuntime.exec() method in dummy jar to call my main jar.

I have hardcoded my main jars path its working fine.But I would like to know how do I get my Main jar's location programmatically when two jars are residing in different location??

I can get path of my dummy jar using approach used in below link.

How to get the path of a running JAR file?

But please advice me to get jar path of my main program..

1
  • Probably the easiest and most portable way is to have your installer create a properties file with all the locations. Commented Jul 18, 2012 at 18:08

1 Answer 1

1

You can't, unless you know where they will be installed/deployed. Why not package them both in the same JAR and then you can find the JAR path using the technique you described?

You should have two classes with main() methods, say org.kittu.Main and org.kittu.Dummy. Package them into main.jar and make sure org.kittu.Dummy is the class that gets executed by default (in the manifest).

In your Dummy class, get the location of main.jar and the amount of memory the user wants then exec() the something like:

java -Xmx <memory> -jar <path to main.jar> org.kittu.Main

to run your Main class.

Sign up to request clarification or add additional context in comments.

6 Comments

Good idea, and you can use OneJar to package everything together.
one jar???You want me to add dummy jar functionality also in my main project?? OK.If am doing in that way, after user's memory selection, are you suggesting me to call runtimr.exec() to execute the jar ?
Yes, what would be the problem with that?
Problem would be again my main program comes to the same point asking user to select memory size.I can avoid this by setting some flag in my own property file during first execution isn't it??correct me if I am wrong.
@Kittu That's right, you can pass a command line parameter, say --run-main-program or something similar.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.