简体   繁体   English

导入java类

[英]Importing java classes

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 我正在尝试使用Google语音的Java API(可从此处获取: http : //code.google.com/p/google-voice-java/ ),google-voice-java-1.6.jar和json。罐

My program is not finding the .jar file for import. 我的程序找不到要导入的.jar文件。 I've made sure my classpath is pointing to the dir containing the jar files. 我确保我的类路径指向包含jar文件的目录。

My code below does not use any of the GV classes, I'm simply trying to import them. 我下面的代码未使用任何GV类,我只是在尝试导入它们。 What am I doing wrong? 我究竟做错了什么? The standard java classes import fine. 标准的Java类可以很好的导入。

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. 我在debian sid下使用Java 6。 I'm also working from the command line. 我也在命令行中工作。 I was setting my classpath as an environment variable in my .bashrc. 我在.bashrc中将类路径设置为环境变量。 My jars are in directory ~/java/classes. 我的罐子在〜/ java / classes目录中。 My source is in ~/java 我的来源在〜/ 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. 如果我注释掉json.jar中的两个导入,则代码运行良好,因此感谢所有提供的类路径提示。

Fixed using -cp "./classes/*" worked. 修复了使用-cp“ ./classes/*”起作用的问题。

Are you using any IDE or compiling the program at command line? 您正在使用任何IDE还是在命令行中编译程序? In any case, setting the classpath to the directory containing the JAR files doesn't work. 无论如何,将类路径设置为包含JAR文件的目录都不起作用。 You have to make sure your classpath lists all the JAR files separately. 您必须确保您的类路径单独列出了所有JAR文件。 Eg 例如

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 6,则可以使用类路径通配符来解决同样的问题。

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? 相关主题: 如何在类路径中使用通配符添加多个jar?

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. 如果您确定已正确包含jar文件,请尝试清理并构建应用程序并将其部署回去。

Worked for me,but i am not sure though. 为我工作,但我不确定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM