简体   繁体   中英

How do I determine the command string eclipse uses to launch my java program?

I've got a simple java program, socket, AWT and jUnit dependencies.

I've built it in eclipse and when I run/debug it from eclipse it works.

When I launch it from the command line I get an error saying

Exception in thread "main" java.lang.NoClassDefFoundError

I'm guessing it's due to not finding one of the required dependencies in the classpath.

Given that launching from eclipse works, Is there a way of determining what command line eclipse uses to launch the same program?

It looks like your classpath isn't set appropriately when you try to run via the command line. You can easily export the command Eclipse uses by doing this:

  1. Run your application and go to your Debug perspective
  2. In the process viewer, there should be an entry for the app you've just executed
  3. Right-click the row that mentions java.exe or javaw.exe
  4. Select Properties
  5. In the dialog that pops up you'll see the Command Line which includes all classpath entries and arguments

The classpath that Eclipse will use should be visible in your project's properties dialog...

Or, on a Unix-like system, you can cheat, with something like (Linux/Fedora) ps axww | grep java ps axww | grep java to peek around for the actual command-line.

On Linux, specifically, /proc/ pid /cmdline will give the entire command-line (split with '\\0' chars, so it may look run-together if you just cat the file) and /proc/ pid /environ will show environment variables, if you need to peek at them, as well. (eg CLASSPATH environment variable)

You're asking 2 different questions here.

You can check your Java project's classpath by right clicking on the project name, and left clicking on the Properties option at the bottom.

On the Properties dialog, left clicking on the Java Build Path brings up the build path dialog.

If you want to determine the Eclipse command line string, you look at the Run Configurations. On the menu, left click on Run, then left click on Run Configurations. Under Java Application, you should find the run configuration for your project. The Arguments tab shows you how Eclipse starts your Java project.

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