1

I'm trying to open an xterm terminal in Java, and run a Java file in it. Here's the Java code that is opening up the terminal:

Process p2 = new ProcessBuilder("xterm", "-hold", "-e", "java", "/home/harry/main.class").start();

xterm opens fine, but it's saying that it can't find the main class home.harry.main.class. I'm using slashes, but they're being changed to dots. What am I doing wrong?

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
RharryR
  • 11
  • 3
  • It's just `main` (not `main.class`); `"java", "-cp", "/home/harry", "main"` – Elliott Frisch Nov 20 '15 at 02:59
  • +Hovercraft Of Eels it is a fully qualified java class. Its just that xterm thinks that the slashes im giving it are periods. Please read my full question. – RharryR Nov 20 '15 at 03:00
  • I agree with Elliot. What happens when you run "xterm -hold -e java /home/harry/main.class" on the command line(or shell)? The way to invoke a java command is to let it know where to find the classes (using -cp) and then to let it know which class you want to run (package+class-name). – user2533521 Nov 20 '15 at 03:09

1 Answers1

1

The mention of xterm is misleading. The question (agreeing with @elliott-frisch and @user2533521) is how to run a Java class on the command-line. The full pathname and classfile name are two aspects which have to be separated.

Not quite a duplicate, these links can give some insight:

That is (referring to the documentation):

  • the "/home/harry" can be specified using the classpath -cp option (see Setting the class path).
  • the ".class" suffix is not useful; only the class name is used (probably "main").
Community
  • 1
  • 1
Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105