Dylan Wheeler
Dylan Wheeler

Reputation: 7074

Java - How to make program run jar files internally

I was wondering ... I want to use a plugin-type thing with my Java program.

Here is the situation:

I have compiled a source file (.java) into a .jar file using MY .JAR program as a library. How to I make MY program run the other .jar file internally (using the main program as a reference).

I know this is weird (it sounds weird to me too), but if anyone understands what I am trying to say, please comment.

Thank you all in advance!

Upvotes: 1

Views: 656

Answers (2)

Carlos Quijano
Carlos Quijano

Reputation: 1576

OK, here's a draft of how to do it.

  • Create an interface with a "run()" method.
  • Your .java plugin must implement that interface.
  • Load the all classes in classpath (help here Find Java classes implementing an interface)
  • run your plugin by executing the run method of the interface.

Upvotes: 2

user1241335
user1241335

Reputation:

You would have to run the jar using the standard syntax. Your question is basically about running console commands inside java. Here is a nice answer to a similar question: link!
This isn't necessarily exactly what you want, but it's goal is to put you on the right track, basically you would get the jar placement, then check for the system, then use the technique used there to run a command through the specific platform's console.

Upvotes: 0

Related Questions