6/15/2006

Set Classpath in Eclipse and NetBeans: a Short Comparison

How to set project classpath in Eclipse and NetBeans are similar: just right-click the project name, choose Properties to bring up the Properties Window. But there are some small variations between the two, mostly of the nature of ease-of-use, or style.

How to set classpath in NetBeans:

In NetBeans Project Properties Window, you click Libraries in the left panel, and in the right panel are 4 categories of classpath you can configure:

  • Compile: Empty by default. Compile-time libraries are automatically propagated to other categories of classpath, so you don't need to repeat the same set of jar files in all 4 categories.

  • Run: By default includes everything in compile-time classpath, and compiled classes (e.g., build/classes).

  • Compile Tests: By default includes everything in compile-time classpath, compiled classes (e.g., build/classes), and JUnit.

  • Run Tests: By default includes classpath for compiling tests, and compiled tests.
The separation of the 4 categories of classpath offers a great deal of flexibility, and in most cases, common-sense default values are used to save configuration efforts. Depending on project types, you may see fewer categories of classpath in NetBeans. For instance, there is no Run classpath for web application project, since we don't directly run a war file.

How to set classpath in Eclipse:

Eclipse manages run classpath and build/compile classpath in different places. To configure run classpath, go to menu Run | Run ... to open up the Run Dialog Window. Your current project should already be selected, otherwise, expand the Java Application node in the left panel and select it. Click Classpath tab in the right panel. The default classpath for the current project is the output folder where all compiled classes reside. You can then click any of these buttons to modify run classpath: Add Projects, Add JARS, Add External JARS, Advanced, etc.

To configure build classpath, in Eclipse Project Properties Window, click Java Build Path in the left panel, and in the right panel choose Libraries tab. There are more classpath-related elements in Eclipse: JARs, External JARS, Variables, Libraries, Class Folders, and other Projects. Click Add External JARs (not Add JARS) if you want to add a jar file to classpath, and click Add Class Folders if you want to add a directory or folder to classpath.

It seems to me Add Variables, Add Libraries, and Add JARS all add collections of classpath elements that are defined inside Eclipse, but I don't know their differences. When I specify classpath in any IDE, I like to explicitly spell out Jar files and directories, without using any IDE-specific artifacts. I suppose the whole purpose of having them is to reuse them in other projects, but I find it's pretty unrealistic due to various jar version differences.

I don't care about the difference between a jar file and a directory, both of them are just an element in the classpath. I like the fact that NetBeans combine them into one single Add JAR/Folder button.

When I create a project in Eclipse 3.2, the default output folder is set to the same folder as source folder, which is not a good idea. At least for me, I don't like mixing class files along with java source files. Wouldn't that also slow down classloading when JVM searches classes, since there are twice as many files to scan. You can change the output folder in project property window | Java Build Path.

67 comments:

Eugene Kuleshov said...

BTW, in Eclipse you can just click on jar or source folder and choose to add it to the build path from the popup menu...

Milind Rao said...

In Eclipse if Project B depends on Project A and Project A needs x.jar and y.jar, I don't need to add them to Project B's classpath while running.

I'm using Netbeans 6.0 and I couldn't get a similar thing going. It's a pain having to add all the dependent projects' jars to the client project.

Secondly, I prefer Eclipse's approach of different buttons for adding folder and jars. If I enter a folder path containing the jars in the File Chooser dialog and hit Enter, it adds the folder to the classpath. In Eclipse, the folder gets opened in the dialog and I can then add the jars in that folder to the classpath.

Anonymous said...

I tried to include the HTTPclient components in my program but always get the error that the package does not exist...

How can I get rid of this??

Shweta said...

I tried to include the HTTPclient components in my program but always get the error that the package does not exist...

How can I get rid of this??

Rajeena said...

I used HttpClient client=new HttpClient();
and added three jar files-
commons-httpclient-3.1.jar,
commons-logging-1.1.1,
commons-pool-1.3
but still showing exception
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.apache.commons.httpclient.HttpClient.(HttpClient.java:66) in the avove line.Can anyone help me?

Angry birds clone said...

Nice post. Great blog. Thanks for sharing. It was very interesting and meaningful.
Fiverr clone script| airbnb clone| Fiverr clone script| Yelp Clone Script|

Logo Design said...

Such a great post share its really very informative post for me.
Keep it up. Banner Design

Kholil(মোঃ খলিলুর রমান) said...

I say many site in blogspot but this is the best site i ever sine. Really, I like your site. Boss, I am hardly interested to learn jave but don't know how to start..

Unknown said...

Kholil,

You can start with Java - Head First book. Learn chapter by chapter and you ll be fine.

List said...

Its not just important to know setting classpath but also How Classpath in Java works, until you know that its difficult to fix issues related to ClassNotFoundException and others.

NANDKISHOR WAGH said...

attractive piece of information, I had come to know about your blog from my friend arjun, ahmedabad,i have read atleast eleven posts of yours by now, and let me tell you, your website gives the best and the most interesting information. This is just the kind of information that i had been looking for, i'm already your rss reader now and i would regularly watch out for the new posts, once again hats off to you! Thanks a lot once again, Regards, Difference Between Classpath and Path

clod said...

Codelobster works much better for me

Etpl Seo said...

Nice post it is very useful for me.
Each and every year we are providing Cheap and best students project at Madurai.

Anna said...

Great and Useful Article.

Online Java Course

Java Online Training

Java Course Online

J2EE training

online J2EE training

Best Recommended books for Spring framework

Java Interview Questions












Java Training Institutes in Chennai

Java Training in Chennai

J2EE Training in Chennai

java j2ee training institutes in chennai

Hitesh Kumar said...

Set Path and Classpath in Java

path is set for use java tool in your java program like java, javac, javap. javac are used for compile the code.
Classpath are used for use predefined class in your program for example use scanner class in your program for this you need to set classpath.

Hitesh Kumar said...

Set Path and Classpath in Java

path is set for use java tool in your java program like java, javac, javap. javac are used for compile the code.
Classpath are used for use predefined class in your program for example use scanner class in your program for this you need to set classpath.

Hitesh Kumar said...

Difference between path and classpath in Java
path is set for use java tool in your java program like java, javac, javap. javac are used for compile the code. and classpath are used for use predefined class in your program for example use scanner class in your program for this you need to set classpath.

Shop The Best Sex Toys said...

You can start with Java - Head First book. Learn chapter by chapter and you ll be fine.

Rahul saini said...

Such a great post share its really very informative post for me.Thanks for sharing....

Karthika Shree said...

Finding the time and actual effort to create a superb article like this is great thing. I’ll learn many new stuff right here! Good luck for the next post buddy..
Java Training in Chennai

lingmaaki said...

Wild cards were introduced from Java 6 . Class path entries can contain the basename wildcard character *, which is considered equivalent to specifying a list of all the files in the directory with the extension .jar or .JAR.

java -cp "lib/*" %MAINCLASS%
Where %MAINCLASS% is the class containing your main method.

More on...Path and ClassPath

http://net-informations.com/java/basics/path.htm

akshaya dharsini said...

Nice blog thanks for sharing useful concept....
Java Training in Chennai

Games 2 Girls said...

I understand what you bring it very meaningful and useful, thanks.
run2online.net

JD Metro Lock Decatur GA said...


this is what we go for
Locksmith Decatur GA

Buford GA Locksmith said...

Yes We all In This Lock and Key Services
Buford Locksmith & Security LLC

G.L.Atlanta Locksmith & Security said...

http://www.locksmithandsecurity.net
Atlanta Locksmith Services

MARIETTA SECURITY LOCKSMITH said...

Marietta GA Locksmith - Locksmith in Marietta GA
locksmith services Marietta GA

Suwanee, GA said...

Suwanee Locksmith Services
Locksmith In Suwanee, GA
Suwanee Lock and Key Services

locksmith Kennesaw GA said...

with all this in our Respect
http://locksmithserviceskennesaw.com/
Locksmith Kennesaw, GA
Kennesaw, GA
Locksmith Services Kennesaw, GA
Locksmith For Car In Kennesaw GA
Residential Locksmith In Kennesaw, GA

Unknown said...

It is a very good blog and useful for students and developer,
Thanks for sharing


Java Online Course

Local Atlanta Locksmith, LLC said...

Atlanta Locksmith
Locksmith In Atlanta GA
Locksmith Services Atlanta, GA
Car lockout In Atlanta GA
Home Lockout Services
Locksmiths
Home door lock instal

Ellenwood Locksmith said...


Locksmith In Ellewood, Ga
Ellenwood GA Locksmiths Services
Ellenwood Locksmith For Home Residence
Emergency Locksmith Services Ellenwood, GA
Locksmith
Car Locksmith

Brain Carve said...

nice post...
Abacus institute Training Class in Chennai

suresh H said...
This comment has been removed by the author.
gowsalya said...

Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
Best Devops training in sholinganallur
Devops training in velachery
Devops training in annanagar
Devops training in tambaram

gowsalya said...

This is most informative and also this post most user friendly and super navigation to all posts... Thank you so much for giving this information to me.. 
Online DevOps Certification Course - Gangboard
Best Devops Training institute in Chennai

john jersy said...

I'm here representing the visitors and readers of your own website say many thanks for many remarkable
online Python training
python training in chennai

hansika hans said...

Excellent blog, I wish to share your post with my folks circle. It’s really helped me a lot, so keep sharing post like this

Java interview questions and answers

Core Java interview questions and answers

Java training in Chennai | Java training in Tambaram

Java training in Chennai | Java training in Velachery

john jersy said...

Very nice post here and thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.
python Online training in chennai
python Online training in bangalore
python interview question and answers

geetha sridhar said...

Appreciating the persistence you put into your blog and detailed information you provide
Data Science training in chennai | Best Data Science training in chennai
Data Science training in OMR | Data science training in chennai
Data Science training in chennai | Best Data science Training in Chennai
Data science training in velachery | Data Science Training in Chennai
Data science training in tambaram | Data Science training in Chennai
Data Science training in anna nagar | Data science training in Chennai

john brito said...

Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.

rpa training in chennai
Best rpa training in bangalore
rpa course in bangalore
rpa training in marathahalli
rpa training in btm
best rpa training in chennai

SRI said...

Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

best rpa training in chennai
rpa training in chennai
rpa interview questions and answers
automation anywhere interview questions and answers
blueprism interview questions and answers
uipath interview questions and answers
rpa training in bangalore

lenin christ said...


Hmm, it seems like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I as well as an aspiring blog writer, but I’m still new to the whole thing. Do you have any recommendations for newbie blog writers? I’d appreciate it.
Top 250+AWS Interviews Questions and Answers 2019 [updated]
Learn Amazon Web Services Tutorials 2019 | AWS Tutorial For Beginners
Best AWS Interview questions and answers 2019 | Top 110+AWS Interview Question and Answers 2019
Best and Advanced AWS Training in Bangalore | Amazon Web Services Training in Bangalore
AWS Training in Pune | Best Amazon Web Services Training in Pune
AWS Online Training 2018 | Best Online AWS Certification Course 2018
Best Amazon Web Services Training in Pune | Best AWS Training in Pune

lenin christ said...

Greetings. I know this is somewhat off-topic, but I was wondering if you knew where I could get a captcha plugin for my comment form? I’m using the same blog platform like yours, and I’m having difficulty finding one? Thanks a lot.

Amazon web services Online Training |Best Online AWS Certification Course
AWS Training in Chennai | Advanced Amazon Web Services Training Institute in Chennai
AWS Training in Bangalore |Best AWS Training in Bangalore

SANDY said...

Greetings. I know this is somewhat off-topic, but I was wondering if you knew where I could get a captcha plugin for my comment form? I’m using the same blog platform like yours, and I’m having difficulty finding one? Thanks a lot.

AWS Online Training |Best Online AWS Certification Course
AWS Training in Chennai | Advanced Amazon Web Services Training Institute in Chennai
AWS Training in Bangalore |Best AWS Training Institute in Bangalore

HACK 7 said...

blogspot
hack7

manisha said...

apple mac service center | apple ipad service center | apple service center | imac service center

Yogayogi said...

Thank you for benefiting from time to focus on this kind of, I feel firmly about it and also really like comprehending far more with this particular subject matter. In case doable, when you get know-how, is it possible to thoughts modernizing your site together with far more details? It’s extremely useful to me
Python Online certification training
python Training institute in Chennai
Python training institute in Bangalore

suresh babu s said...

Greetings! Very helpful advice within this blog
Python Training in Bangalore

Best Institute For Python Training in Marathahalli

Best Python Training Institutes in Bangalore

Python Training Center in Bangalore BTM

class in Bangalore marathahalli

python courses in Bangalore

suresh babu s said...

I really like reading through a post that can make people think. Also, many thanks for permitting me to comment!
Angular 2 Training in bangalore
Angular 4 Training in bangalore
Angular 5 Training in bangalore
Angular 6 Training in bangalore
Angular 7 Training in bangalore
Angular 2 Institute in bangalore
Angular 4 Courses in bangalore
Angularjs Classes
Angularjs Training in Bangalore ,
Angularjs Training Institute Bangalore ,
AngularJS Classes in Bangalore
Python Training in Bangalore

Anexas Europe said...

I think this is the best article today about the future technology. Thanks for taking your own time to discuss this topic, I feel happy about that curiosity has increased to learn more about this topic.Artificial Intelligence Training in Bangalore. Keep sharing your information regularly for my future reference.

siva said...

Great Article… I love to read your articles because your writing style is too good,
its is very very helpful for all of us and I never get bored while reading your article because,
they are becomes a more and more interesting from the starting lines until the end.
Java training in Annanagar
Java training in Chennai
Java training in Chennai
Java training in Electronic city
Java training in Marathahalli

Naveen said...

Thank you for excellent article.

Please refer below if you are looking for best project center in coimbatore


soft skill training in coimbatore
final year projects in coimbatore
Spoken English Training in coimbatore
final year projects for CSE in coimbatore
final year projects for IT in coimbatore
final year projects for ECE in coimbatore
final year projects for EEE in coimbatore
final year projects for Mechanical in coimbatore
final year projects for Instrumentation in coimbatore

MyTraining said...

Nice Information

AWS Training in Bangalore

Best AWS Training Institute in Bangalore

Soumitasai said...

Very nice post here thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.


Check out : big data training in velachery
big data analytics training and placement
big data training in chennai chennai tamilnadu
big data workshop in chennai

IT Tutorials said...

Really useful information. Thank you so much for sharing.It will help everyone.Keep Post. RPA training in chennai | RPA training in Chennai with placement | UiPath training in Chennai | UiPath certification in Chennai with cost

Amirtha Gowri said...

Really Happy to say your post is very interesting. Keep sharing your information regularly for my future reference. Thanks Again.

Check Out:
big data training in chennai chennai tamil nadu
big data training in velachery
big data hadoop training in velachery

Jagadeesh said...

Thanks for sharing this Valuable information. I like this blog.
Digital marketing training institute in bangalore offers, Digital Marketing Course in Bangalore.

Alpharetta Locksmith Pro said...

Locksmith Residential Alpharetta, GA
Alpharetta Locksmiths
Locksmith In Alpharetta, GA
24 Hour Locksmith In Alpharetta
Alpharetta GA Locksmiths
Locksmith

Diya shree said...

Good job and thanks for sharing such a good blog You’re doing a great job. Keep it up !!

PMP Certification Fees | Best PMP Training in Chennai |
pmp certification cost in chennai | PMP Certification Training Institutes in Velachery |
pmp certification courses and books | PMP Certification requirements |
PMP Training Centers in Chennai | PMP Certification Requirements | PMP Interview Questions and Answers

vyshu kits2019 said...

Nice blog thanks for sharing useful concept....

Amazon Web Server Online Training


AWS Interview Questions and Answers

lock and Key Services said...

locksmith Services In Atlanta GA
push Bar Locksmith In Atlanta GA
Push bar Locksmith Atlanta GA
locksmith For your Office
http://alpharettalocksmithpro.com







kavithasathish said...

This is an awesome blog for the people who are really seeking information for this technology.
TOEFL Coaching in Chennai
TOEFL Center in Chennai
Best Spoken English Class in Chennai
french classes
pearson vue
German Classes in Chennai
TOEFL Coaching in OMR
TOEFL Coaching in Porur

Locksmith In Dunwoody said...

dunwoody Home Lockouts Locksmith
dunwoody CarLocouts Locksmith
dunwoody Automotive Locksmith
dunwoodyResidential Locksmith
dunwoody Commercial Locksmith

local Alpharetta Locksmith, LLC said...

Alpharetta Locksmith
Alpharetta GA Locksmith
Locksmith Alpharetta, GA
Alpharetta Locksmith Services

Kaushalesh Group said...

Thanks for valuable information

Unichrone said...

Nice information
You may also try this
PMP Certification Training Toronto Canada