*
The moose likes Beginning Java and the fly likes Eclipse and CLASSPATH Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Eclipse and CLASSPATH" Watch "Eclipse and CLASSPATH" New topic
Author

Eclipse and CLASSPATH

john sayeau
Ranch Hand

Joined: Aug 23, 2010
Posts: 33
Does anyone know how to set my classpath globally (for all projects) on eclipse?
I know how to do it from the os and then use the jdk to compile but I'd like to not have to set it up on every eclipse project.

I'm going through a text book that uses the same classes regularly and I 'd like to not have to add the build path to each project individually.

Thanks.
Ed Ward
Ranch Hand

Joined: Jan 30, 2006
Posts: 147
Hi John.

I think this should probably be over in IDEs, Version Contol and other tools but I'll give it a go anyway.

I'm not in front of an Eclipse window at the moment but I am using RAD which is based on Eclipse.
In RAD if I go to "WINDOW->Preferences->Java->Build Path" off the menu there is an entry for Classpath Variables and User Libraries. It's may not be exactly the same for straight Eclipse but should be similar.

Hope this helps.

...Actually after poking around over in the IDE forum I realized that what I said above may not be what you're asking.
Have a look at this thread, it may be more helpful http://www.coderanch.com/t/106042/vc/Eclipse-add-log-properties-classpath
Except for all the log4j static of course.

john sayeau
Ranch Hand

Joined: Aug 23, 2010
Posts: 33
I've been there and it asks for a variable name and a folder path.
I tried the folder path and guessed at a variable name "mindview" (arbitrarily picked) and it didn't work.
Ed Ward
Ranch Hand

Joined: Jan 30, 2006
Posts: 147
Why are you guessing at a variable name? This is where you define the path variable. You will still likely need to add it to each project. Defining it here simply makes it easier to do so. You may be able to setup a project template in Eclipse, but that is beyond me.
Sorry can't be of more assitance.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37874
    
  22
How to define a global CLASSPATH for all applications? Answer: not at all. You should neither set a system-wide CLASSPATH on the OS nor on an IDE if at all possible. If you need to set anything to compile, that would be the PATH. If you are getting anything to compile at all, you probably have a correct PATH already, and should not change anything else.
For each application, you can set the classpath with the -cp option. This is better, since each application will need a different classpath.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3815

john sayeau wrote:Does anyone know how to set my classpath globally (for all projects) on eclipse?...

I'm not sure why you are trying to do this in the first place. If you are using your own build script (Ant etc...) within the Eclipse then you can define the relevant classes/libraries in the script itself. Or if you rely on the Eclipse generated project then you don't have to worry, you just have to add the libraries etc.. in the Java build path of the project. After all each project has different dependencies.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3573
    
  14

Campbell Ritchie wrote:How to define a global CLASSPATH for all applications? Answer: not at all. You should neither set a system-wide CLASSPATH on the OS nor on an IDE if at all possible. If you need to set anything to compile, that would be the PATH. If you are getting anything to compile at all, you probably have a correct PATH already, and should not change anything else.
For each application, you can set the classpath with the -cp option. This is better, since each application will need a different classpath.

I like to declare at least one global classpath, because I generally use the command line to run my programs, and for some quick test programs I am too lazy to type the classpath in the prompt. But that's neither here nor there.
john sayeau
Ranch Hand

Joined: Aug 23, 2010
Posts: 33
I want to do this because I'm working my way through the "Thinking in java" book. I downloaded a bunch of classes from the author's site and they are in one folder. When I'm experimenting with some of the code in the book I find I almost always have to use import to access his classes. I'd like not to have to set up every little project I do to be able to import that namespace. These are not real world projects , just learning exercises. If there was a way to do this globally while I'm going through the book, it would save me some time doing a repetitive task.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37874
    
  22
Stephan van Hulst wrote: . . . I like to declare at least one global classpath, . . .
What does it read? I would only use one "global" classpath . . . "." And there is no point in setting that, unless something else has already set its own global classpath.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Eclipse and CLASSPATH
 
Similar Threads
How to package a web project
How to run a java project in command line.
Web service with a jdbc connection
About ".classpath" file in the project
Eclispe and classpath