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?

3
  • It's just main (not main.class); "java", "-cp", "/home/harry", "main" Commented Nov 20, 2015 at 2: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. Commented Nov 20, 2015 at 3: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). Commented Nov 20, 2015 at 3:09

1 Answer 1

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").
Sign up to request clarification or add additional context in comments.

Comments

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.