1

I'm developing an application which has a Launcher class which has the following code to execute the application main class and it has the following code.

public class Launcher {

private static final String jarName = "LDC_MCM.jar";
private static final String mainClassWithPackageName = "com.ars.ldcmcm.Application";

public static void main(String[] args) {
    String path = Configuration.getInstance().getAppFolder();
    String cmd = "java -XX:+ForceTimeHighResolution  -cp "+path+"\\"+jarName+" "+ mainClassWithPackageName;
    System.out.println("invoking... \n"+cmd);
    try {
            Runtime.getRuntime().exec(cmd);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

} 

When I saw that my application is not starting I tried running my jar through a batch file with the following commands.

java -jar LDC_MCM.jar

The result of the execution is given below.

F:\SMC>java -Dfile.encoding=UTF-8 -jar LDC_MCM.jar
invoking...
java -XX:+ForceTimeHighResolution  -cp F:\SMC\LDC_MCM.jar com.ars.ldcmcm.Application

The execution stays like this the application does not start. Can someone tell why the application stays like this without my application main starting. I have tried roll backing my code to an older version to see if it is anything related to the application code.

Please post a comment if you require any additional details. com.ars.ldcmcm.Application will set up a frame for a swing application.

I tried on more thing in regards this. I tried running the command directly through command prompt and I got an exception as given below.

F:\>java -XX:+ForceTimeHighResolution  -cp F:\SMC\LDC_MCM.jar com.ars.ldcmcm.Application
Exception in thread "main" java.lang.NullPointerException
    at com.ars.ldcmcm.Application.main(Application.java:283)

Since there is an exception in the application class I tried running the application main via eclipse, the application started as expected.

Manesh
  • 53
  • 8
  • what is `com.ars.ldcmcm.Application` do? or what's your expected output. – TomN Jul 29 '16 at 05:49
  • It is a package in my application which has the main functions to trigger all my threads related to the application. – Manesh Jul 29 '16 at 05:52
  • will it setting up a `Frame` or print any output? how did you know it's not running. the command is fine, it should run up if the file path is correct. – TomN Jul 29 '16 at 06:04
  • 1
    If you just run the `java -XX:+ForceTimeHighResolution -cp F:\SMC\LDC_MCM.jar com.ars.ldcmcm.Application` command directly do you get the same result? If so, the problem is with that application and information you give in this question can't help. – Alexey Romanov Jul 29 '16 at 06:27
  • what is line 283 in `Application.java`? maybe you miss something before calling `Application.java`(declare or initialization) so it return the exception. – TomN Jul 29 '16 at 06:55
  • You test `java -jar xxx` from commandline and in the code you write `java -cp xxx` and then you compare the results – Stefan Hegny Jul 29 '16 at 08:00

1 Answers1

0

See if this makes any difference:

public static void main(String[] args) {
String path = Configuration.getInstance().getAppFolder();
String cmd = "java -XX:+ForceTimeHighResolution  -cp "+path+"\\"+jarName+" "+ mainClassWithPackageName;
System.out.println("invoking... \n"+cmd);
Process p;
try {
       P = Runtime.getRuntime().exec(cmd);
       p.waitFor();
       System.out.println("Script executed successfully");
} catch (Exception e) {
    e.printStackTrace();
}

}

ma3stro
  • 313
  • 2
  • 11
  • You might want to use 'Error Stream' to collect output if there is no exception is caught. There is a good example in this link: [http://stackoverflow.com/questions/13008526/runtime-getruntime-execcmd-hanging] – ma3stro Jul 29 '16 at 06:23
  • And if that does not help could you try using ProcessBuilder class: http://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html – ma3stro Jul 29 '16 at 06:25