0

I've been attempting to import a class contained with in a .jar file. My my_package.jar file resides in /Users/user/Library/Java/Extensions and my ~/.bashrc contains the following line export CLASSPATH = "$CLASSPATH:/Users/user/Library/Java/Extensions. At the top of my program is a line that reads import my_package.MyClass;. Whenever I try to compile the program using javac MyProgram.java I get the package my_package does not exist. I've done a bit of searching around online and found several possible fixes. One of which involved moving the .jar file to the current directory and invoking javac found here as follows.

javac -cp '.:my_package.jar' MyClass.java

This yields the same error.

I have also tried changing the CLASSPATH to /Users/David_Johnson/Library/Java/Extensions/ and /Users/David_Johnson/Library/Java/Extensions/*. They both yield the same error.

It appears as though I am missing something quite trivial. Any help in catching my mistake would be greatly appreciated.

I'm on Max OSX 10.8.5 using javac 1.7.0_07

Community
  • 1
  • 1
PhiloEpisteme
  • 857
  • 3
  • 8
  • 19

1 Answers1

0

CLASSPATH must explicitly list each and every JAR file. Wildcards or directories are not supported.

You can use bash to generate the list though.

for jar in /Users/where/ever/they/are/*.jar
do
    CLASSPATH="$CLASSPATH:$jar"
done
export CLASSPATH
anttix
  • 7,709
  • 1
  • 24
  • 25
  • I've included your suggestion exactly as you described and I still get the same error. I tried compiling with javac MyClass.java. I made sure to source my ~/.bashrc after implimenting the change you've suggested. I checked my CLASSPATH using echo to verify that the correct .jar file was now included in the CLASSPATH and it indeed is. – PhiloEpisteme Mar 13 '14 at 18:11