0

I tried to create jar file using command line that I inserted into java code, but it didn't work. The java code was like this:

try {
   Runtime a = Runtime.getRuntime();
   a.exec("cmd cd E:/My data/Final Project/Uji Coba bikin Jar & E: & jar cfm D:/EditingDiniApp.jar META-INF/MANIFEST.MF EditingDini META-INF net org");
} catch (IOException ex) {
   Logger.getLogger(JarFactory.class.getName()).log(Level.SEVERE, null, ex);
}

I copied the command into cmd.exe and it worked, but if it embed into java, it won't work.

Was there anything that I miss to do?

Thanks..

3
  • 1
    OH LAWD! Please consider Ant. Commented Jun 15, 2012 at 17:12
  • Is this to package up a project or as a function the project is supposed to do while running? Commented Jun 15, 2012 at 17:15
  • there's an article talking about this. basically, you need consume the OutputStream Commented Jun 15, 2012 at 17:22

1 Answer 1

1

Write the code to create a jar in a file through java code. Name it xxx.bat. Thread.sleep(5000);

And then use the exec command to execute the bat file. This works for me.

EDIT:

String s = "cmd cd E:/My data/Final Project/Uji Coba bikin Jar & E: & jar cfm     
D:/EditingDiniApp.jar META-INF/MANIFEST.MF EditingDini META-INF net org";
FileOutputStream fos = new FileOutputStream("abc.bat");
fos.write(s.getBytes());
fos.close();
Thread.sleep(2000);
Runtime.getRuntime().exec("abc.bat");
Thread.sleep(2000);

By the way I thought you are doing this for fun. But if you are new to java, I would suggest using Ant. Ant is used for packaging applications , deploying etc etc in java http://ant.apache.org

Sign up to request clarification or add additional context in comments.

1 Comment

I'm new in java.. would you help me with an example? Thanks a lot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.