javac -cp /home/alan/jars main
"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." -- Ted Nelson
J. Kevin Robbins wrote:I generally recommend that people avoid using the $CLASSPATH environment variable. It just leads to headaches like this. You should be able to specify the directory where your jar files are located like so:
javac -cp /home/alan/jars main
You can't combine the $CLASSPATH and the -cp option. When you use -cp or -classpath it takes precedence over the environment variable.
"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." -- Ted Nelson
J. Kevin Robbins wrote:You shouldn't need to specify the full jar file name in either the environment variable or the -cp option, only the directory or directories where the jars are located.
Think of it like the $PATH environment variable in Windows or *nix. You don't specify the name of each executable file, only the directories where the executables are located.
J. Kevin Robbins wrote:You shouldn't need to specify the full jar file name in either the environment variable or the -cp option, only the directory or directories where the jars are located.
Experience keeps a dear School, but Fools will learn in no other.
---
Benjamin Franklin - Postal official and Weather observer
Tim Holloway wrote:
Thinking that you could just point to a directory full of JARs and have all the classes in all the JARs automatically available is one of the oldest newbie problems in the book.
Tim Holloway wrote:"globbing" ("-cp classdirectory/*.jar") doesn't work in most shells. I think that the JVM would have had to have had glob support built into it, and they probably ruled that out for security reasons and/or because globs are all-or-nothing operations.
Tim Holloway wrote:
There are cases where you do have directories full of Jars. One such is the Tomcat webapp server. However, if you look at its startup script, you'll discover that the script reads the Tomcat lib directory and adds each jar as an element in the classpath that it builds before launching the Tomcat JVM.
CLASSPATH=.:/usr/share/tomcat5/common/lib/:/usr/share/tomcat5/bin/
Class paths to the JAR, zip or class files. Each class path should end with a file name or directory depending on what you are setting the class path to, as follows:
For a JAR or zip file that contains class files, the class path ends with the name of the zip or JAR file.
For class files in an unnamed package, the class path ends with the directory that contains the class files.
For class files in a named package, the class path ends with the directory that contains the root package, which is the first package in the full package name.
Multiple path entries are separated by semicolons with no spaces around the equals sign (=) in Windows and colons in Oracle Solaris.
The default class path is the current directory. Setting the CLASSPATH variable or using the -classpath command-line option overrides that default, so if you want to include the current directory in the search path, then you must include a dot (.) in the new settings.
Class path entries that are neither directories nor archives (.zip or JAR files) nor the asterisk (*) wildcard character are ignored.
"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." -- Ted Nelson