Indeed ItIs
Indeed ItIs

Reputation: 257

Setting classpath for a jar and a class

I need to set the classpath for servlet-api.jar and another class in order to compile a file.java. How could I accomplish that? I have tried

javac -cp /path/to/servlet-api;/home/user/Desktop/Other.class file.java

However it does not work.

Any help? I am aware it's possible to set the environment variable however I would like to know if it's possible manually. Thanks

Upvotes: 0

Views: 80

Answers (1)

JB Nizet
JB Nizet

Reputation: 692161

The classpath must contain jar files, and directories. Directories must be directories containing the root of a package tree. So, assuming Other is in the package com.foo.bar, and its class file is /home/user/Desktop/com/foo/bar/Other.class, the classpath should be

-cp /path/to/servlet-api.jar:/home/user/Desktop

Note that : is the path separator on Unix. ; is for Windows. I assume you're not on Windows since your path is /home/... and not c:\home\...

PS: If Other is not in any package, then fix that. Classes should always be in a package.

Upvotes: 1

Related Questions