Question

I am trying a run a java program(which is not in eclipse) from within eclipse using

Process p1 = Runtime.getRuntime().exec("java " + exec); 

(where exec is the path to the file)

It throws me a could not find or load main class. It actually has a main class and it did compile successfully with the following statement. any help would be appreciated

Process p = Runtime.getRuntime().exec(compiler + " " + file);
Était-ce utile?

La solution

From your comments it seems that your command should probably look like

java -cp c:\users test

so try changing your code to something like

Process p1 = Runtime.getRuntime().exec("java -cp c:\\users " + exec); 

where exec should pass full.package.name.of.YourClass which in your case is most probably test (not test.class or test.java).

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top