简体   繁体   中英

Java ProcessBuilder using periods in a string rather than slash when passing parameters

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?

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").

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM