unix中的java classpath [英] java classpath in unix
问题描述
我可以使用以下设置在cygwin + windows中运行java(sw / jar目录有几个jar文件,我从java命令行中选择相关的文件):
I can run java in cygwin+windows using the following settings (the sw/jar directory has several jar files, and I pick the relevant one from the java command line):
CLASSPATH=.;C:\sw\java_6u35\lib\\*;C:\sw\jar\\*
java org.antlr.Tool Calc.g
但是我在linux下运行时遇到以下问题:
But I am having the following problems when running in linux:
(1)我无法在类路径中设置目录名,以下行报告错误:
(1) I can't set a directory name in a classpath, the following line reports an error:
setenv CLASSPATH .:/sw/jdk1.6.0_35/lib/\*:/sw/jar/*
(2)当我用-jar选项显式运行时,我仍然收到错误:
(2) when I run explictly with -jar option, I still get an error:
java -jar /sw/jar/antlr-3.4.jar org.antlr.Tool Calc.g
error(7): cannot find or open file: org.antlr.Tool
但是,该类确实存在。当我做 jar tf /sw/jar/antlr-3.4.jar
时,我得到:
However, the class does exist. When I do jar tf /sw/jar/antlr-3.4.jar
, I get:
...
org/antlr/Tool.class
所以我的问题是:(a)如何在unix中指定我的jar目录是包含几个jar文件的xxx,以及(2)如何在运行时从这个dir中选择相关的jar?
So my question is: (a) how do I specify in unix that my jar-directory is xxx that contains several jar files, and (2) how do I pick the relevant jar from this dir at runtime?
推荐答案
要直接在java命令中指定目录中的多个jar,请使用此
To specify multiple jars in a directory, directly in the java command, use this
java -cp/ sw / jar / *org.antlr.Tool Calc.g
java -cp "/sw/jar/*" org.antlr.Tool Calc.g
这将包括所有的罐子
如果你想在Unix / Linux系统中设置类路径,请使用这个
If you want to set the classpath in Unix/Linux systems, use this
export CLASSPATH = / sw / jar / a.jar:/sw/jar/b.jar
export CLASSPATH=/sw/jar/a.jar:/sw/jar/b.jar
这篇关于unix中的java classpath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!