I’m starting a Java programming class at UCSD next week and I’m trying to prepare over the weekend. There is a library called objectdraw.jar which comes with the book we will be using for our class projects. I am currently using Vim for my Java projects because most assignments will be simple and I am still trying to learn and master Vim.
Now to the question:
In C++ I am able to use #include with angled brackets <> to include headers in a default folder and #include with quotes “” to include local header files. It seems from what I’ve found with some Internet searches that you can’t do that with Java.
I tried putting the objectdraw.jar file in the same folder as my .java file for the first assignment, but it doesn’t find the library using the following code:
import java.awt.*;
import objectdraw.*;
When I searched online, the Gentoo HOWTO mentioned setting a CLASSPATH but then mentions that those instructions should be considered deprecated, but doesn’t provide further instructions.
The website where I downloaded the library http://eventfuljava.cs.williams.edu/library.html does not provide instructions for Vim, but does for other IDEs like Eclipse and Netbeans.
Can anyone tell me where I would place the .jar file to ALL my projects can find it, or can anyone point me to a resource where I might find an answer. I seem to be asking the wrong questions when searching online.
Thanks!
Look here for how to set classpath using command line options to any of the java sdk tools – java, javac. The page shows how to set the environment variable CLASSPATH as well as how to use the switch -classpath.
In your case if you have the objectdraw.jar in the same directory as your source files, then you will need a command like this to compile –
and this to run
You can also provide the full path to a jar file in the classpath and add multiple directories and jars. Such as
-classpath .:/path/to/my.jar:/some/other/directorynote paths and separators for *nix environment. on Windows it would be ; and \Edit: Note comment below for quoting paths with spaces in them.