Reputation: 1711
I am running Ubuntu 11.10 and have installed jdk-6u30-linux-i586.bin and have a directory /usr/local/jdk1.6.0_30 and everything was working and compiling fine even without a CLASSPATH so long as I had export PATH=/usr/local/jdk1.6.0_30/bin:$PATH in my ~/.bashrc and executed java from a fresh new shell (not sure why no CLASSPATH is needed in my env).
Now I am trying to use the following class libraries: http://code.google.com/p/google-api-java-client/downloads/list google-api-java-client-1.6.0-beta.zip
I downloaded and extracted the zip file to a /usr/local/google directory which now contains all the jar files. I then try to compile the BigQuerySample from http://code.google.com/p/google-api-java-client/wiki/ClientLogin
$ javac -cp /usr/local/google BigQuerySample.java
and I get:
BigQuerySample.java:1: package com.google.api.client.googleapis does not exist import com.google.api.client.googleapis.*;
and so on for all the imported packages except for java.io.*;
I know this should be a simple classpath problem but adjusting the classpath on the command line or in the environment with export CLASSPATH=$CLASSPATH:/usr/local/google does not get rid of the errors. I have tried jar -tvf *jar for each jar file and the stuff is there, so why is the java compiler not finding the includes?
Thanks,
John Goche
Upvotes: 1
Views: 7180
Reputation: 374
You may try this:
javac -Djava.ext.dirs=/usr/local/google BigQuerySample.java
Upvotes: 1
Reputation: 274532
You need to add the jar to your classpath like this:
javac -cp "$CLASSPATH:/usr/local/google/google-api-client-1.6.0-beta.jar" BigQuerySample.java
Or use a wildcard to add all jars:
javac -cp "$CLASSPATH:/usr/local/google/*:/usr/local/google/dependencies/*" BigQuerySample.java
Upvotes: 2
Reputation: 2336
When including jars in the classpath either specifically indicate the jars to include or use wildcards to include all jars in a directory. So for your example you could use:
javac -cp /usr/local/google/google-api.jar BigQuerySample.java
or
javac -cp /usr/local/google/* BigQuerySample.java
For more help using including jars in the classpath see this post.
Upvotes: 1
Reputation: 7736
You will have to explicitly specify all the references JARs.
javac -cp /usr/local/google/file1.jar:/usr/local/google/file2.jar:. BigQuerySample.java
Same thing while running...
java -cp /usr/local/google/file1.jar:/usr/local/google/file2.jar:. BigQuerySample
Upvotes: 1