9 Replies - 6877 Views - Last Post: 21 September 2012 - 04:04 AM Rate Topic: -----

#1 binarymatter  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 18-September 12

Opening another jar file within a java application

Posted 20 September 2012 - 12:05 AM

Hello all,

Is there anyway to open another jar application from your java application and allsow send arguments to that appliction you wish to open.

I would like to construct a application with small jars that send arguments to each other and opening them for certain task. That would make updating certain part of my application( jars ) easy

Thank you
Is This A Good Question/Topic? 0
  • +

Replies To: Opening another jar file within a java application

#2 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2250
  • View blog
  • Posts: 5,340
  • Joined: 10-September 10

Re: Opening another jar file within a java application

Posted 20 September 2012 - 12:43 AM

You've already done this in almost every program you've written using the "import" statement.
Was This Post Helpful? 0
  • +
  • -

#3 binarymatter  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 18-September 12

Re: Opening another jar file within a java application

Posted 20 September 2012 - 12:54 AM

Thank you for the reply

But what i mean is i created a main program wich i compliled in a jar file , allsow created another jar file that is somthing totaly diffrent , what i would like to do is , in the main jar code i would like to open the other jar with some code and send some arguments to that jar

Thank you
Was This Post Helpful? 0
  • +
  • -

#4 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2250
  • View blog
  • Posts: 5,340
  • Joined: 10-September 10

Re: Opening another jar file within a java application

Posted 20 September 2012 - 02:40 AM

You can use the contents of the .jar files and do anything you want with them within the bounds of Java programming. Your rebuttal suggests that you think I didn't understand the original question or that you disagreed with my first answer, but I don't understand why in either case. Your second post restates the original question without adding new information.

If necessary, post a simple example of source code contained in two .jar files and restate your question in the context of how that source code does not perform as you would like. I think we've sufficiently discussed the theory and need to move the discussion to an application to make progress. However, as my original post stated, I think you've accomplished what you're asking many times in code you've already written (assuming you've written some) and just don't realize it.
Was This Post Helpful? 0
  • +
  • -

#5 binarymatter  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 18-September 12

Re: Opening another jar file within a java application

Posted 20 September 2012 - 03:27 AM

Ok thank you for the reply

i found the answer
Runtime.exec("java -jar trang.jar 5-something.xml 5.1-somethingElse.xsd");

Was This Post Helpful? 0
  • +
  • -

#6 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2250
  • View blog
  • Posts: 5,340
  • Joined: 10-September 10

Re: Opening another jar file within a java application

Posted 20 September 2012 - 03:39 AM

Okay. That's an answer to a different question.

You won't want to use that approach with a lot of .jar files at the same time, because I believe you'll be running each in its own JVM which will have a significant memory impact. You should consider the import approach as that's the way Java is intended to work, and running each class file in its own JVM may have limitations - will have, eventually - that you may find unacceptable.

Good luck!

This post has been edited by GregBrannon: 20 September 2012 - 03:48 AM

Was This Post Helpful? 1
  • +
  • -

#7 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3425
  • View blog
  • Posts: 15,496
  • Joined: 20-September 08

Re: Opening another jar file within a java application

Posted 20 September 2012 - 09:16 AM

For the reason Gregg gave, you'd probably be better off (if every jar is not already on the classpath) to use a custom classloader and then call the main method of the application class directly
Was This Post Helpful? 1
  • +
  • -

#8 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8376
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Opening another jar file within a java application

Posted 20 September 2012 - 11:43 AM

import MyClass.classContainingMain;

...
    String[] args = {"something.xml", "5.1-somethingElse.xsd"};
    MyClass.classContainingMain.main(args);


should do

This post has been edited by pbl: 20 September 2012 - 12:43 PM
Reason for edit:: added the classContainingMain

Was This Post Helpful? 1
  • +
  • -

#9 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3425
  • View blog
  • Posts: 15,496
  • Joined: 20-September 08

Re: Opening another jar file within a java application

Posted 20 September 2012 - 12:34 PM

That's what i suggested ;) Of course, you need to import package+class
Was This Post Helpful? 1
  • +
  • -

#10 binarymatter  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 18-September 12

Re: Opening another jar file within a java application

Posted 21 September 2012 - 04:04 AM

Thank you all for the help :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1