I'm busy working with servlets now and when I try and compile them, I get erorrs stating that it can't find javax.servlet etc. Getting errors where I do the import statements to them.

So apparently I have to add that servlet.jar file to the CLASSPATH? And that file can be located (since I'm using Tomcat) under Tomcat\common\lib\servlet-api.jar.
So what I wana know is, what really is this "classpath" I've worked with it before a little, so I made stuff work without knowing what the classpath is in the first place..

Plus to add more things to the classpath, do you just use a " ; " in between the deff paths? as in Whatever\somefolder\thatfile.txt; Tomcat\common\lib\servlet-api.jar?

Recommended Answers

All 5 Replies

It is the "path" on which "class"es will be searched for by the jvm/compiler.

Edit: And don't do this on the system environment CLASSPATH variable. I know I have told you this already, if running from a web container/app server place jars in the META-INF/lib directory (usually), if running/compiling from an IDE add the jars as references/libraries in the project properties/preferences for that project, if running from the command line using the -jar option then properly define the classpath attribute in the manifest file, if running/compiling from the command without the -jar option then use the -cp option.

Thank you! A short, plain English answer.. Other websites go completely over the top and leave me even more confuzed that before.
As for adding more classes to the ClassPath, do you just seperate them with a semicolon? ;

Yes (on windows). That, however, is a system question.

Thanks man! Really appreciate your help, you seem to have completely taken over the Java Forum here on DaniWeb. The only person that ever replies...

Click

Thanks man! Really appreciate your help, you seem to have completely taken over the Java Forum here on DaniWeb. The only person that ever replies...

Well you just offended another 8 people at least that are regulars here

Besides as masijade mentioned you shouldn't be messing with CLASSPATH or PATH variable, only in rarely cases, usually very old libraries requires you to add them there.
In day-to-day task you will add any necessary library through IDE or if more experienced you will use Maven to take of it for you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.