chollida
chollida

Reputation: 7894

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?

Upvotes: 7

Views: 1641

Answers (3)

Gilbert Le Blanc
Gilbert Le Blanc

Reputation: 51445

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.

Upvotes: 1

Chris
Chris

Reputation: 23171

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

Upvotes: 14

BRPocock
BRPocock

Reputation: 13914

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 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. (e.g. CLASSPATH environment variable)

Upvotes: 1

Related Questions