Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: How would you run jar file with a java program?

  1. #1
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default How would you run jar file with a java program?

    I tried the Runtime.getRuntime() and the Process exec() method, but it said that the jar wasn't a valid Win 32 Application. So what should I do instead of going the route like I would with an .exe?


  2. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: How would you run jar file with a java program?

    The executable you have to run is java (or javaw.exe) passing it the -jar and any other arguments including the name of the jar file.

  3. The Following User Says Thank You to pbrockway2 For This Useful Post:

    javapenguin (May 31st, 2012)

  4. #3
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: How would you run jar file with a java program?

    Say I had a file called file.jar, how would I pass that using the Runtime.getRuntime() and Process exec() method then?

  5. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: How would you run jar file with a java program?

    Runtime.exec("java -jar myjarfile.jar")

    But unless you don't know anything about the internals aspects of the jar (and making the assumption that the JRE is on the PATH of the client machine - which in many cases it is not), you should be able to add this to your classpath and run it internal to your application.

  6. The Following User Says Thank You to copeg For This Useful Post:

    javapenguin (May 31st, 2012)

  7. #5
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: How would you run jar file with a java program?

    How would you know if the JRE is on the client machine or not? And if it's not, how do you get it there?

Similar Threads

  1. Find the important class in ".mse" file using Java program
    By ashwarth21 in forum Java Theory & Questions
    Replies: 3
    Last Post: March 13th, 2012, 07:43 PM
  2. how to edit hosts file in windows7 using java program ?
    By vijay_p in forum Java Theory & Questions
    Replies: 3
    Last Post: December 2nd, 2011, 07:14 AM
  3. How to run program from jar file?
    By jammy in forum Java ME (Mobile Edition)
    Replies: 0
    Last Post: March 28th, 2011, 08:39 AM
  4. Opening a file with a java program
    By hafunui in forum Java Theory & Questions
    Replies: 4
    Last Post: March 1st, 2011, 04:52 PM
  5. java program to copy a text file to onother text file
    By francoc in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: April 23rd, 2010, 03:10 PM