0

I'm trying to make use of a java api for google voice (available here: http://code.google.com/p/google-voice-java/ ), google-voice-java-1.6.jar and json.jar

My program is not finding the .jar file for import. I've made sure my classpath is pointing to the dir containing the jar files.

My code below does not use any of the GV classes, I'm simply trying to import them. What am I doing wrong? The standard java classes import fine.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;

import gvjava.org.json.JSONException;
import gvjava.org.json.JSONObject;

import com.techventus.server.voice.Voice;
import com.techventus.server.voice.datatypes.AllSettings;
import com.techventus.server.voice.datatypes.DisabledForwardingId;
import com.techventus.server.voice.datatypes.Group;
import com.techventus.server.voice.datatypes.Phone;
import com.techventus.server.voice.datatypes.Greeting;
import com.techventus.server.voice.exception.CaptchaRequiredException;
import com.techventus.server.voice.util.ParsingUtil;

@SuppressWarnings("deprecation")


class hello {

static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static String pass = null;

public static void main(String args[])

  {
System.out.println("Enter Your name:");   

{

try {
          pass = br.readLine(); }

    catch (IOException ioe) {
      System.out.println("IO error trying to read input!");
      System.exit(1); }


     System.out.println(pass);

  } 
 } 
}

I'm using java 6 under debian sid. I'm also working from the command line. I was setting my classpath as an environment variable in my .bashrc. My jars are in directory ~/java/classes. My source is in ~/java

java $ javac -cp ./classes/* hello.java 
javac: invalid flag: ./classes/json.jar
Usage: javac <options> <source files>

If I comment out the two imports from json.jar the code runs fine, so thanks all for the classpath tips.

Fixed using -cp "./classes/*" worked.

Alan
  • 1,265
  • 4
  • 22
  • 44
  • Please show how you 'made sure' that the libs are on the classpath. There are a lot of traps... – Andreas Dolk Aug 15 '10 at 15:42
  • "My program is not finding the jar file for import". Do you mean your *compiler* isn't? Which IDE/compiler are you using? How have you told your IDE / compiler about the jars? – meriton Aug 15 '10 at 15:45

2 Answers2

2

Are you using any IDE or compiling the program at command line? In any case, setting the classpath to the directory containing the JAR files doesn't work. You have to make sure your classpath lists all the JAR files separately. E.g.

java -cp your/dir/of/jars pkg.Main // won't work in Java 5 and below

java -cp your/dir/of/jars/first.jar;your/dir/of/jars/second.jar pkg.Main // works

If you are using Java 6, you can use classpath wildcards to resolve the same.

java -cp your/dir/of/jars/* pkg.Main // works in Java 6

Related thread: How to use a wildcard in the classpath to add multiple jars?

Community
  • 1
  • 1
sasuke
  • 6,589
  • 5
  • 36
  • 35
0

If you are sure that you have included your jar files properly ,try clean and building the application and deploy it back.I had a similar experience where in everything seemed normal but i did not clean and build app again.

Worked for me,but i am not sure though.

Barry
  • 1,585
  • 3
  • 22
  • 35