Adding JAR to CLASSPATH in Mac OS
I am trying to set up the CLASSPATH for Java under Mac OS.
Specifically I am trying to add a couple of JAR archives to it.
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 i开发者_运维知识库t 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.
Is there a solution?
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:
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.
精彩评论