macos 在 Mac OS 中将 JAR 添加到 CLASSPATH
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5028286/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adding JAR to CLASSPATH in Mac OS
提问by Tiago Veloso
I am trying to set up the CLASSPATH for Java under Mac OS.
我正在尝试在 Mac OS 下为 Java 设置 CLASSPATH。
Specifically I am trying to add a couple of JAR archives to it.
具体来说,我正在尝试向其中添加几个 JAR 档案。
If I do it like:
如果我这样做:
## Setting up ASM bytecode instructor library
export CLASSPATH=$CLASSPATH:/Users/fork/Dev/ASM/lib/all/asm-all-3.3.1.jar
It works fine. However, if I set it like the documentation recommends:
它工作正常。但是,如果我按照文档建议的方式设置它:
## Setting up ASM bytecode instructor library
export CLASSPATH=$CLASSPATH:/Users/fork/Dev/ASM/lib/all/*
It does not seem to work.
它似乎不起作用。
The thing is that I want to add, let's say 10 jars, it sounds impractical to add one-by-one.
问题是我想加,比如说10罐,一一加听起来不切实际。
Is there a solution?
有解决办法吗?
采纳答案by Erik
You must set the jars on the classpath individually. There are ways around this though. One that I use is starting the java app with a shell script that contains something like this:
您必须单独在类路径上设置 jar。有办法解决这个问题。我使用的一个是使用包含以下内容的 shell 脚本启动 java 应用程序:
cd $JAR_DIR
jars=($(ls *.jar))
JAR_PATH=""
dir=$(pwd)
for i in "${jars[@]}"; do
JAR_PATH="${JAR_PATH}:$dir/$i"
done
CLASSPATH=$CLASSPATH:$JAR_PATH
This will work.
这将起作用。