3 Replies - 186 Views - Last Post: 17 May 2014 - 03:09 PM Rate Topic: -----

#1 wviper3  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 55
  • Joined: 06-October 13

Compile multiple Jar files into one from inside Java Program

Posted 17 May 2014 - 11:29 AM

I am trying to compile multiple jar files into one jar file from inside a java program. I know how to do this with shell scripts but I would rather have a universal application than one that will only run on Mac, Windows, or Linux. This is my current compiler code:
if(System.getProperty() == "Mac OS X"){
    Runtime.getRuntime().exec("javac -classpath jar1.jar; jar2.jar");
}


I would then continue this on for Linux and Windows, but this limits my application. Can I do this another way?
Thanks, wviper3

Is This A Good Question/Topic? 0
  • +

Replies To: Compile multiple Jar files into one from inside Java Program

#2 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2675
  • View blog
  • Posts: 11,296
  • Joined: 20-September 08

Re: Compile multiple Jar files into one from inside Java Program

Posted 17 May 2014 - 02:16 PM

You're get a little mixed up here:

Quote

I am trying to compile multiple jar files into one jar file

Quote

Runtime.getRuntime().exec("javac -classpath jar1.jar; ...


The only things that get compiled in Java are source files. What is produced are class files.
Was This Post Helpful? 0
  • +
  • -

#3 wviper3  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 55
  • Joined: 06-October 13

Re: Compile multiple Jar files into one from inside Java Program

Posted 17 May 2014 - 02:22 PM

How then do I extract the contents from multiple jar files and package them into one Jar file?
Was This Post Helpful? 0
  • +
  • -

#4 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2675
  • View blog
  • Posts: 11,296
  • Joined: 20-September 08

Re: Compile multiple Jar files into one from inside Java Program

Posted 17 May 2014 - 03:09 PM

That's not a trivial operation. For instance, each jar could have info in META-INF. How are those to be made into one? If you ignore that potential problem, it would be a case of using the JarFile class (see api docs)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1