Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Question about package in Eclipse
Question about package in Eclipse [message #654734] Wed, 16 February 2011 21:08 Go to next message
Teal_Candle is currently offline Teal_CandleFriend
Messages: 1
Registered: February 2011
Junior Member
Try to keep this simple. So I create helloWorld in Eclipse. Runs and compiles just fine in Eclipse. Here is what the looks like:

/**
*
*/
package Folder1.Folder2.Folder3

/**
* @author Teal_Candle
*
*/
public class helloWorld
{

/**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
System.out.println("Can you see me?");

}

}

Now when I trying running this in cmd in Windows, it gives me the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: Folder1/Folder2/Folder3/h
elloWorld
Caused by: java.lang.ClassNotFoundException: Folder1.Folder2.Folder3.helloWorld
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: Folder1.Folder2.Folder3.helloWorld. Program will exi
t.

However if I take the package Folder1.Folder2.Folder3; out of the beginning of my file, Eclipse throws an error saying its expecting a package, however if I save the file and compile outside of eclipse it then runs fine.

How do I run this simple program cmd? And before anyone suggest to just move this file to the root folder of the project, that won't work for the project I'm working on, I need to be able to separate all this mini little programs into different folders.

Any help would be highly appreciated!!!

Thanks
Teal_Candle
Re: Question about package in Eclipse [message #654739 is a reply to message #654734] Wed, 16 February 2011 21:49 Go to previous messageGo to next message
Olivier Thomann is currently offline Olivier ThomannFriend
Messages: 518
Registered: July 2009
Senior Member
Do you have the current folder on the classpath ?
How do you invoke this class from the command line ?
--
Olivier
Re: Question about package in Eclipse [message #654740 is a reply to message #654734] Wed, 16 February 2011 21:50 Go to previous message
Russell Bateman is currently offline Russell BatemanFriend
Messages: 3268
Registered: July 2009
Location: Provo, Utah, USA
Senior Member

On 16-Feb-11 14:09, Teal_Candle wrote:
> [snip]
> Now when I trying running this in cmd in Windows, it gives me the
> following error:
>
> Exception in thread "main" java.lang.NoClassDefFoundError:
> Folder1/Folder2/Folder3/helloWorld
> Caused by: java.lang.ClassNotFoundException:
> Folder1.Folder2.Folder3.helloWorld
> at java.net.URLClassLoader$1.run(Unknown Source)
> at java.security.AccessController.doPrivileged(Native Method)
> at java.net.URLClassLoader.findClass(Unknown Source)
> at java.lang.ClassLoader.loadClass(Unknown Source)
> at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
> at java.lang.ClassLoader.loadClass(Unknown Source)
> Could not find the main class: Folder1.Folder2.Folder3.helloWorld.
> Program will exit.

You've not created a "runnable" JAR, right? You can't generate a common
("library") JAR and run it. Use File -> Export -> Java -> Runnable JAR
File... see if you can't figure it out from there. (Or, did you do this
and I'm just not reading your problem?)

> However if I take the package Folder1.Folder2.Folder3; out of the
> beginning of my file, Eclipse throws an error saying its expecting a
> package, however if I save the file and compile outside of eclipse it
> then runs fine.
> [snip]

As long as your Java file is down inside a package, the package
statement at the top of the file must match the package it's in.

Russ
Previous Topic:Possible Documentation Bug?
Next Topic:can 2 plugins have same key bindings
Goto Forum:
  


Current Time: Sun Dec 21 13:46:51 GMT 2014

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

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