Adding JAR to CLASSPATH in Mac OS

南笙酒味 提交于 2019-12-04 12:07:38

问题


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 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.

Is there a solution?


回答1:


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.



来源:https://stackoverflow.com/questions/5028286/adding-jar-to-classpath-in-mac-os

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!