Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Eclipse cannot find external Java class, compile error
Eclipse cannot find external Java class, compile error [message #68007] Tue, 24 May 2005 06:13 Go to next message
Eclipse UserFriend
Originally posted by: roland.goecke.anu.edu.au

Hi,

the following problem is driving me nuts. I would appreciate if someone
could provide an answer.

I've got a Java application project under Eclipse that requires an
external class from a package provided by someone on the internet (no
Eclipse project or similar, just a package of Java classes like
com.xyz.class1 etc). That package and the external class sit in a
directory structure like the following on my hard disk:

D:\ExternalPackages\com\xyz\class1\class1.class

My project sits in another directory like:

D:\MyProject\project.java

If I try to compile it outside of Eclipse in a comand-line environment
using javac and where I have set my computer's environment variable
CLASSPATH to include D:\ExternalPackages, it works like a charm and I
can run the application.

However, I cannot get this to compile under Eclipse, as the class1 class
is not found. So I guess that means that Eclipse doesn't use the same
classpath. Does Eclipse ignore a CLASSPATH variable set system-wide?

I could solve the problem by importing the class but that creates a copy
of the class under MyProject\ when all I want is to "link" to it. Or I
can go to Project\Properties\Java Build Path and add the folder there
under Source, but then again it copies all the classes from com.xyz to
my project rather than linking to the existing copy. The Libraries tab
in the same window only allows the inclusion of external jars or folders
under the MyProject\ directory.

How do I setup Eclipse to show the same behaviour as the command-line
example?

I am running Eclipse 3.0.2 on Win XP SP2.

Cheers,
Roland
Re: Eclipse cannot find external Java class, compile error [message #68691 is a reply to message #68007] Tue, 24 May 2005 13:33 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: wegener.cboenospam.com

Roland Goecke wrote:

> Hi,

> the following problem is driving me nuts. I would appreciate if someone
> could provide an answer.

> I've got a Java application project under Eclipse that requires an
> external class from a package provided by someone on the internet (no
> Eclipse project or similar, just a package of Java classes like
> com.xyz.class1 etc). That package and the external class sit in a
> directory structure like the following on my hard disk:

> D:ExternalPackagescomxyzclass1class1.class

> My project sits in another directory like:

> D:MyProjectproject.java

> If I try to compile it outside of Eclipse in a comand-line environment
> using javac and where I have set my computer's environment variable
> CLASSPATH to include D:ExternalPackages, it works like a charm and I
> can run the application.

> However, I cannot get this to compile under Eclipse, as the class1 class
> is not found. So I guess that means that Eclipse doesn't use the same
> classpath. Does Eclipse ignore a CLASSPATH variable set system-wide?

> I could solve the problem by importing the class but that creates a copy
> of the class under MyProject when all I want is to "link" to it. Or I
> can go to ProjectPropertiesJava Build Path and add the folder there
> under Source, but then again it copies all the classes from com.xyz to
> my project rather than linking to the existing copy. The Libraries tab
> in the same window only allows the inclusion of external jars or folders
> under the MyProject directory.

> How do I setup Eclipse to show the same behaviour as the command-line
> example?

> I am running Eclipse 3.0.2 on Win XP SP2.

> Cheers,
> Roland

On the Libraries tab select Add Class Folder. From the Edit Class Folder
dialog select Create New Folder. From the next dialog, click Advanced.
Check Link to Folder In File System. You can then Browse to the location
or define a Variable to provide a location relative to workspace variable.

I would recommend using the Variable if you are going to share this
project with other developers. That way, each can define the location in
their own workspaces without everyone having to have the class folder at
the same location in their directory hiearchy.
Re: Eclipse cannot find external Java class, compile error [message #69006 is a reply to message #68691] Wed, 25 May 2005 06:39 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: roland.goecke.anu.edu.au

Dave Wegener wrote:

> On the Libraries tab select Add Class Folder. From the Edit Class
> Folder dialog select Create New Folder. From the next dialog, click
> Advanced. Check Link to Folder In File System. You can then Browse to
> the location or define a Variable to provide a location relative to
> workspace variable.
>
> I would recommend using the Variable if you are going to share this
> project with other developers. That way, each can define the location
> in their own workspaces without everyone having to have the class folder
> at the same location in their directory hiearchy.

Thanks, Dave. It works to the extent that it now compiles, but...

....when trying to run it from within Eclipse (using Run -> Run) I get
the following error message:

java.lang.NoClassDefFoundError: ExternalPackages/com/xyz/class1/class1
at project.main(project.java:21)
Exception in thread "main"

and the execution stops with a "Fatal exception occured. Program will exit."

I tried adding the classpath with the VM argument -classpath
D:\ExternalPackages in the Run dialogue but that didn't help. In fact,
that shouldn't be necessary anyway because it already appears under the
Classpath tab under User Entries.

Hmm? Any ideas?

Cheers,
Roland
Re: Eclipse cannot find external Java class, compile error [message #69435 is a reply to message #69006] Wed, 25 May 2005 21:57 Go to previous message
Eclipse UserFriend
Originally posted by: eclipse.rizzoweb.com

Roland Goecke wrote:
> Thanks, Dave. It works to the extent that it now compiles, but...
>
> ...when trying to run it from within Eclipse (using Run -> Run) I get
> the following error message:
>
> java.lang.NoClassDefFoundError: ExternalPackages/com/xyz/class1/class1
> at project.main(project.java:21)
> Exception in thread "main"

That message indicates that it is trying to load a class named class1 in
a package ExternalPackages.com.xyz.class1
I doubt that is correct - ExternalPackages should not be part of the
package name, right? I'm not sure how it would compile correctly either,
unless the package really is named "ExternalPackages.com.xyz.class1"
instead of just "com.xyz.class1"

In other words, it seems like your classpath is not quite set up right
as you thought it was. What exactly is the package name of the external
class(es)? And how, exactly, do you have the build path set? And how,
exactly, is the Run path set?

Eric
Previous Topic:JREs and Ant
Next Topic:ScrolledForm from a Main() method
Goto Forum:
  


Current Time: Wed Apr 24 23:25:39 GMT 2024

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

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

Back to the top