2013年8月14日 星期三

java--classpath


javac -classpath ./:/usr/share/tomcat6/lib/* tableRead.java


java-classpath

run : 
export CLASSPATH=/usr/share/tomcat6/lib/itextpdf-5.1.3.jar:$CLASSPATH
java HelloWorld


javac -classpath ./:/usr/share/apache-tomcat-7.0.35/lib/servlet-api.jar file1.java

javac -classpath /usr/share/apache-tomcat-7.0.35/lib/servlet-api.jar file2.java

export CLASSPATH=/hr/WEB-INF/lib/mysql-connector-java-5.1.23-bin.jar:$CLASSPATH

export CLASSPATH=/home/appnetix/LOG4J_HOME/log4j-1.2.16.jar

export CLASSPATH=$CLASSPATH:/home/appnetix/LOG4J_HOME/log4j-1.2.16.jar

export CLASSPATH=$CLASSPATH:/home/appnetix/LOG4J_HOME/log4j-1.2.16.jar:.

inf : http://docs.oracle.com/javase/7/docs/technotes/tools/windows/classpath.html

Class paths to the .jar, .zip or .class files. Each classpath should end with a filename or directory depending on what you are setting the class path to:
  • 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 (the first package in the full package name).
Multiple path entries are separated by semi-colons. With the set command, it's important to omit spaces from around the equals sign (=).
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, you must include "." in the new settings.
Classpath entries that are neither directories nor archives (.zip or .jar files) nor * are ignored.

CLASSPATH="/home/denislav/Download/;/home/denislav/"
java -cp /home/denislav/Desktop/ myfirstjavaprog
java -version
javac -classpath MyJar.jar GetJar.java 
For Linux and other Unix variants

If you are using bash as your command shell, open .bash_profile in your favorite text editor. You should already have one in your home directory. If not, you can create it. If you use another shell (i.e. ksh, csh, etc.), they run similar profile scripts when loging in. I don't know what the file names are for these other shells, though. If all else fails, you should be able to use .profile instead, which is usually executed no matter which shell you use. For my text editor, I like emacs, so the command line looks something like this:
        emacs .bash_profile
The syntax is similar to the autoexec.bat file in Windows 9x/ME. Add something similar to the following lines to the .bash_profile file:
        CLASSPATH=.:/usr/local/fubar/Foo.jar:/home/johndoe/myclasses
        export CLASSPATH
Notice that subdirectories are separated with a forward slash (/) and complete paths are separated with a colon (:). This is typical for any Unix-like operating system.
There are no spaces before or after the = sign.
The . at the beginning of the list includes the current directory in the class path. This is necessary for Java to be able to find .java and .class files in the current directory.
The second "entry" refers to a jar file. Use an appropriate path and file name here.
The last "entry" refers to the base directory where other classes can be found. Most likely, it contains other subdirectories that correspond to appropriate package names.
CLASSPATH .:\j2sdk1.4.2_09\bin;.




沒有留言:

張貼留言