Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » running java from outside eclipse(cannot run a java program outside of eclipse after compiling and running inside eclipse)
running java from outside eclipse [message #654474] Tue, 15 February 2011 22:48 Go to next message
Ralph Boland is currently offline Ralph BolandFriend
Messages: 2
Registered: February 2011
Junior Member
Using tutorial at:
http://www.vogella.de/articles/Eclipse/article.html
I was able to create and run a Java program in Eclipse 3.6 but was unable to run
the program from outside of Eclipse. I would like to know how to run my program
from outside of Eclipse.

In detail:

The tutorial is for Windows but I am using Linux (Ubuntu 10.10).
Following the tutorial I created a project tutorial.first containing a package tutorial.first.
In the package I created a Java file: MyFirstClass2.java which I successfully
compiled and ran from within Eclipse. The source is:

<
package tutorial.first;

public class MyFirstClass2 {

/**
* @param args
*/
public static void main(String[] args) {
System.out.println("Well Hello Eclipse!");

}

}
>

I then created a Jar file MyProgram2.java which Eclipse placed in directory:
~/Eclipse/Java/Workspace.

I then went to this directory and ran command:

java -classpath MyProgram2.jar tutorial.first.MyProgram2

I expected this command to run but got instead the stack trace:

<
Exception in thread "main" java.lang.NoClassDefFoundError: tutorial/first/MyProgram2
Caused by: java.lang.ClassNotFoundException: tutorial.first.MyProgram2
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294 )
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: tutorial.first.MyProgram2. Program will exit.
>

I then ran unzip on the jar file. It created directory:
META-INF containing file: MANIFEST.MF with contents:
Manifest-Version: 1.0

I checked directory ~/Eclipse/Java/Workspace/tutorial/first
and it contains file: MyFirstClass2.class
of size 580 bytes.

In my inexperienced eyes everything is OK and the program should run.

Why doesn't it?

Thanks in advance for any help.

Ralph Boland
Re: running java from outside eclipse [message #654479 is a reply to message #654474] Tue, 15 February 2011 23:02 Go to previous messageGo to next message
Russell Bateman is currently offline Russell BatemanFriend
Messages: 3798
Registered: July 2009
Location: Provo, Utah, USA
Senior Member

On 15-Feb-11 15:48, Ralph Boland wrote:
> Using tutorial at:
> http://www.vogella.de/articles/Eclipse/article.html I was able to create
> and run a Java program in Eclipse 3.6 but was unable to run
> the program from outside of Eclipse. I would like to know how to run my
> [snip]
>
> Why doesn't it?
>
> Thanks in advance for any help.
>
> Ralph Boland

This forum doesn't support Lars' tutorials. There's a Google group for
that as recounted in the meta areas of his website
(http://groups.google.com/group/vogella?pli=1).
Re: running java from outside eclipse [message #654655 is a reply to message #654474] Wed, 16 February 2011 15:08 Go to previous messageGo to next message
Eric Rizzo is currently offline Eric RizzoFriend
Messages: 3070
Registered: July 2009
Senior Member
On 2/15/11 5:48 PM, Ralph Boland wrote:
> Using tutorial at:
> http://www.vogella.de/articles/Eclipse/article.html I was able to create
> and run a Java program in Eclipse 3.6 but was unable to run
> the program from outside of Eclipse. I would like to know how to run my
> program
> from outside of Eclipse.
>
> In detail:
>
> The tutorial is for Windows but I am using Linux (Ubuntu 10.10).
> Following the tutorial I created a project tutorial.first containing a
> package tutorial.first.
> In the package I created a Java file: MyFirstClass2.java which I
> successfully
> compiled and ran from within Eclipse.
<...>
>
> I then created a Jar file MyProgram2.java which Eclipse placed in
> directory:
> ~/Eclipse/Java/Workspace.
>
> I then went to this directory and ran command:
>
> java -classpath MyProgram2.jar tutorial.first.MyProgram2

Your main class is named MyFirstClass2, but you're trying to run a class
named MyProgram2.
Your command line should be
java -classpath MyProgram2.jar tutorial.first.MyFirstClass2

The JAR name and the main class name are separate, orthogonal; they
don't have to match.

Eric
Re: running java from outside eclipse [message #654691 is a reply to message #654474] Wed, 16 February 2011 17:06 Go to previous messageGo to next message
Ralph Boland is currently offline Ralph BolandFriend
Messages: 2
Registered: February 2011
Junior Member
> > ...
> > I then created a Jar file MyProgram2.java which Eclipse placed in
> > directory:
> > ~/Eclipse/Java/Workspace.
> >
> > I then went to this directory and ran command:
> >
> > java -classpath MyProgram2.jar tutorial.first.MyProgram2

> Your main class is named MyFirstClass2, but you're trying to run a class
> named MyProgram2.
> Your command line should be
> java -classpath MyProgram2.jar tutorial.first.MyFirstClass2

> The JAR name and the main class name are separate, orthogonal; they
> don't have to match.

> Eric

Thanks for the help Eric but unfortunately the error you pointed out is an error
in transcribing on my part. I originally typed the command as you propose I
type it now.

Regards,

Ralph Boland
Re: running java from outside eclipse [message #656050 is a reply to message #654691] Wed, 23 February 2011 21:25 Go to previous message
Eclipse UserFriend
Originally posted by: peter.kennedy.blueskyspectroscopy.com

Hi Ralph. I'm working at Blue Sky now.

I think you do have a class name problem - the trace you show refers to
MyProgram2:

> Exception in thread "main" java.lang.NoClassDefFoundError:
> tutorial/first/MyProgram2
> Caused by: java.lang.ClassNotFoundException: tutorial.first.MyProgram2

but your jar's manifest shows MyClass2.

If you want, send me your source and I'll take a look.

----
Peter
Previous Topic:External Tool error..?
Next Topic:Cannot send email to project emailing list... 450 4.7.1 Helo command rejected: Host not found
Goto Forum:
  


Current Time: Thu Apr 18 12:28:13 GMT 2024

Powered by FUDForum. Page generated in 0.03250 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top