Skip to main content



      Home
Home » Newcomers » Newcomers » Help with java CLASSPATH in Eclipse
Help with java CLASSPATH in Eclipse [message #69415] Wed, 25 May 2005 16:44 Go to next message
Eclipse UserFriend
Hi,

I'm new to Eclipse, and trying to figure out how to configure something that
I think should be simple to do, but can't get working. How do you do the
equivalent of setting the CLASSPATH in Eclipse? Here's a simple example
illustrating what I'm trying to do:

I created a java project named "test" using Eclipse in a workspace of "C:\".
In directory C:\test, I created the following file "test.java":

import com.acme.util.*;
public class test {
public static void main (String[] args) {
testUtil.sayHi();
}
}

In C:\javautil\com\acme\util, I have a file testUtil.java:

package com.acme.util;
public class testUtil {
public static void sayHi() {
System.out.println("Hi!\n");
}
}

If I drop to a command prompt, set my "CLASSPATH=.;C:\javautil", cd to
C:\test, I can compile the program test.java with javac and run it with no
problem. In Eclipse, I'm told "The import com.acme cannot be resolved". How
do I tell Eclipse to look for the com.acme.util package under the
C:\javautil root? I've tried adding a variable pointing to this directory in
Project Properties -> Java Build Path -> Libraries -> Add Variable, but
can't get Eclipse to look there. I don't want to import testUtil.java into
my "test" project, as this copies the source to C:\test. I just want to
reference the testUtil.class where it is so I can import the package in
test.java. I would think that this should be simple to do, but maybe not?

Thanks in advance for any replies.
Re: Help with java CLASSPATH in Eclipse [message #69473 is a reply to message #69415] Wed, 25 May 2005 18:14 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse.rizzoweb.com

Ed Brown wrote:
> Hi,
>
> I'm new to Eclipse, and trying to figure out how to configure something that
> I think should be simple to do, but can't get working. How do you do the
> equivalent of setting the CLASSPATH in Eclipse? Here's a simple example
> illustrating what I'm trying to do:
>
> I created a java project named "test" using Eclipse in a workspace of "C:\".
> In directory C:\test, I created the following file "test.java":
>
> import com.acme.util.*;
> public class test {
> public static void main (String[] args) {
> testUtil.sayHi();
> }
> }
>
> In C:\javautil\com\acme\util, I have a file testUtil.java:
>
> package com.acme.util;
> public class testUtil {
> public static void sayHi() {
> System.out.println("Hi!\n");
> }
> }
>
> If I drop to a command prompt, set my "CLASSPATH=.;C:\javautil", cd to
> C:\test, I can compile the program test.java with javac and run it with no
> problem. In Eclipse, I'm told "The import com.acme cannot be resolved". How
> do I tell Eclipse to look for the com.acme.util package under the
> C:\javautil root? I've tried adding a variable pointing to this directory in
> Project Properties -> Java Build Path -> Libraries -> Add Variable, but
> can't get Eclipse to look there. I don't want to import testUtil.java into
> my "test" project, as this copies the source to C:\test. I just want to
> reference the testUtil.class where it is so I can import the package in
> test.java. I would think that this should be simple to do, but maybe not?

On the surface, what you did (adding a variable to the build path)
should have worked. The problem is, I think, that a Library variable
must resolves to a JAR or ZIP, not a directory. Verify this by selecting
the variable entry in your Libraries tab and clicking the edit button -
it will probably tell you in the dialog that it does not point to an
existing archive. (there should also be a warning at the top of the
project properties dialog, above the Libraries tab).
You have a couple of options:
1) JAR up the external library into a JAR or ZIP file and point Eclipse
to that
2) Create a linked folder in your project that links to the c:\javautil
directory. (Do this by creating a new folder at the root of your
project, but in the creation dialog choose the "Advanced" button.) You
can then add this linked folder as a "Class Folder" on the Libraries tab.

HTH,
Eric
Re: Help with java CLASSPATH in Eclipse [message #69839 is a reply to message #69473] Thu, 26 May 2005 10:06 Go to previous messageGo to next message
Eclipse UserFriend
Thanks very much for the reply.

I tried your second suggestion, creating a linked folder in the project
root, and adding it as a "Class Folder" on the Libraries tab. This
eliminated the "import com.acme cannot be resolved" error. However, when I
try to run the program, I now get the error "Required library cannot denote
external folder: 'C:\javautil' for project test". What does this message
mean?

Thanks,
-Ed

"Eric Rizzo" <eclipse@rizzoweb.com> wrote in message
news:d72tje$53d$1@news.eclipse.org...
> Ed Brown wrote:
>> Hi,
>>
>> I'm new to Eclipse, and trying to figure out how to configure something
>> that I think should be simple to do, but can't get working. How do you do
>> the equivalent of setting the CLASSPATH in Eclipse? Here's a simple
>> example illustrating what I'm trying to do:
>>
>> I created a java project named "test" using Eclipse in a workspace of
>> "C:\". In directory C:\test, I created the following file "test.java":
>>
>> import com.acme.util.*;
>> public class test {
>> public static void main (String[] args) {
>> testUtil.sayHi();
>> }
>> }
>>
>> In C:\javautil\com\acme\util, I have a file testUtil.java:
>>
>> package com.acme.util;
>> public class testUtil {
>> public static void sayHi() {
>> System.out.println("Hi!\n");
>> }
>> }
>>
>> If I drop to a command prompt, set my "CLASSPATH=.;C:\javautil", cd to
>> C:\test, I can compile the program test.java with javac and run it with
>> no problem. In Eclipse, I'm told "The import com.acme cannot be
>> resolved". How do I tell Eclipse to look for the com.acme.util package
>> under the C:\javautil root? I've tried adding a variable pointing to this
>> directory in Project Properties -> Java Build Path -> Libraries -> Add
>> Variable, but can't get Eclipse to look there. I don't want to import
>> testUtil.java into my "test" project, as this copies the source to
>> C:\test. I just want to reference the testUtil.class where it is so I can
>> import the package in test.java. I would think that this should be simple
>> to do, but maybe not?
>
> On the surface, what you did (adding a variable to the build path) should
> have worked. The problem is, I think, that a Library variable must
> resolves to a JAR or ZIP, not a directory. Verify this by selecting the
> variable entry in your Libraries tab and clicking the edit button - it
> will probably tell you in the dialog that it does not point to an existing
> archive. (there should also be a warning at the top of the project
> properties dialog, above the Libraries tab).
> You have a couple of options:
> 1) JAR up the external library into a JAR or ZIP file and point Eclipse to
> that
> 2) Create a linked folder in your project that links to the c:\javautil
> directory. (Do this by creating a new folder at the root of your project,
> but in the creation dialog choose the "Advanced" button.) You can then add
> this linked folder as a "Class Folder" on the Libraries tab.
>
> HTH,
> Eric
Re: Help with java CLASSPATH in Eclipse [message #70805 is a reply to message #69839] Fri, 27 May 2005 14:10 Go to previous message
Eclipse UserFriend
Originally posted by: eclipse.rizzoweb.com

Ed Brown wrote:
> Thanks very much for the reply.
>
> I tried your second suggestion, creating a linked folder in the project
> root, and adding it as a "Class Folder" on the Libraries tab. This
> eliminated the "import com.acme cannot be resolved" error. However, when I
> try to run the program, I now get the error "Required library cannot denote
> external folder: 'C:\javautil' for project test". What does this message
> mean?

I've never seen that one before, but it seems to indicate that for
runtime configurations you can't use a linked external folder on the
classpath. I can't think of why not (but I'm not an Eclipse developer so
that doesn't really mean much ;-).
In your Run configuration Classpath tab, remove the linked folder and
then click the Advanced... button - there you can had an external folder
to the runtime classpath. That should work.

I would probably just JAR the classes up - it would seem to be simpler
all around.

HTH,
Eric
Previous Topic:Sort methods in java with eclipse
Next Topic:Eclipse not compiling
Goto Forum:
  


Current Time: Fri May 09 06:49:01 EDT 2025

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

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

Back to the top