• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

java jar Question

 
Ranch Hand
Posts: 151
MyEclipse IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello everyone

i wrote 5 programs and i have their jar files
now what i want is to make a main class that instantiate these 5 jars in loop again and again ..... is there any way to call the jar files in the java class ??


something like this its demo code
 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

is there any way to call the jar files in the java class

You can't call jar file. Using java -jar you can invoke a particular class from the jarfile. But that requires Main-Class entry into the manifest.mf file of the specific jar file.
 
akhter wahab
Ranch Hand
Posts: 151
MyEclipse IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Soumyajit Hazra wrote:

is there any way to call the jar files in the java class

You can't call jar file. Using java -jar you can invoke a particular class from the jarfile. But that requires Main-Class entry into the manifest.mf file of the specific jar file.



can you please provide me the demo or any Good link to understand it in depth??
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the JARs are correctly in your classpath, you don't even need to execute the java command. You can just call the main method of the class like any other static method, using "MainClass.main(...)", where MainClass is the class holding the main method, and ... are the parameters you need to pass.
 
Soumyajit Hazra
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try Jar File Basics
 
akhter wahab
Ranch Hand
Posts: 151
MyEclipse IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christophe Verré wrote:If the JARs are correctly in your classpath, you don't even need to execute the java command. You can just call the main method of the class like any other static method, using "MainClass.main(...)", where MainClass is the class holding the main method, and ... are the parameters you need to pass.



need more explanation i developed all these programs in net-beans and each program is itself a project now i have to run these projects from single class
 
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The main method is still a public static method. That means that you can call it from Java code as well, as long as the class is on the class path. Simply create a String[] with the arguments you want to pass to it, then call that method.
 
akhter wahab
Ranch Hand
Posts: 151
MyEclipse IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Prime wrote:The main method is still a public static method. That means that you can call it from Java code as well, as long as the class is on the class path. Simply create a String[] with the arguments you want to pass to it, then call that method.



thanks Rob it really helps me allot ... now i am doing same as you said mean i made one main class that calls the main classes of five programs that i want to execute but now i have one more problem suppose each main class takes almost 10 mins to execute so programs takes 50 mins to execute... what i want is to start the all main classes at a time so that they will take 10 mins to execute
 
akhter wahab
Ranch Hand
Posts: 151
MyEclipse IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what i want is to instantiate All the 5 programs at a time
 
Rob Spoor
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
java.lang.Thread
 
akhter wahab
Ranch Hand
Posts: 151
MyEclipse IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Prime wrote:java.lang.Thread



i got it Rob thanks
 
Rob Spoor
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome.
 
Tongue wrestling. It's not what you think. And here, take this tiny ad. You'll need it.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic