1

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

johngoche9999
  • 1,641
  • 2
  • 14
  • 21

4 Answers4

2

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
dogbane
  • 266,786
  • 75
  • 396
  • 414
  • Thanks, unfortunately some of the classes from the example are not defined in the jar files which means the example is no good. I have checked it with: for i in *jar; do /usr/local/jdk1.6.0_30/bin/jar -tvf $i >> out; done but no trace of the GoogleTransport class. – johngoche9999 Jan 18 '12 at 17:41
  • The `ClientLogin` API is legacy. I believe you need to use `OAuth` now. See if you can find an updated example. – dogbane Jan 18 '12 at 17:50
1

You may try this:

javac -Djava.ext.dirs=/usr/local/google BigQuerySample.java
Qinghao
  • 274
  • 2
  • 11
  • Hi, that worked as far as the complaints from the includes goes but there are still symbols which the java compiler cannot find such as GoogleTransport, JSONCParser, etc... – johngoche9999 Jan 18 '12 at 17:28
  • I am not sure if you have downloaded all libraries required. You may check if all libraries are under this directory including GoogleTransport etc. And if you want to run this app, you also need to set the option: java -Djava.ext.dirs=... – Qinghao Jan 18 '12 at 17:35
1

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
Web User
  • 7,438
  • 14
  • 64
  • 92
1

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.

Community
  • 1
  • 1
Jonathan Dixon
  • 2,316
  • 23
  • 29