Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 297
Tiago Veloso Avatar asked Feb 17 '11 10:02

Tiago Veloso


1 Answers

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.

like image 63
Erik Avatar answered Oct 18 '22 09:10

Erik