如何在Java中安装GSON模块 [英] How do I install the GSON module in Java

查看:138
本文介绍了如何在Java中安装GSON模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下载了Google JSON模块a.k.a GSON。我在Windows系统上你能告诉我如何安装GSON模块吗?我将JAR提取到了我的类路径中的以下文件夹中:

  C:\程序文件\Java\jdk1 .6.0_07\\lib 

..但是当我输入时:

  import com.google.gson.Gson; 
import com.google.gson.GsonBuilder;

我仍然收到一个找不到模块的错误。

我在做什么错了? >
  • 您不应该提取JAR。
  • 不应将第三方库放在 JDK / lib

  • 您需要在类路径中使用 -cp -classpath 参数。例如

      java -cp。; / path / to / gson.jar com.example.MyClass 

    为了节省每次输入时间,请使用 .bat 文件执行它。



    如果您实际上使用Eclipse之类的IDE,那么您也可以右键单击Java项目,选择 Build Path ,然后然后将其添加为新的 Library 。然后,Eclipse将自动将它放入编译时和运行时类路径中。


    I downloaded the Google JSON module a.k.a GSON. I'm ona windows system Could you tell me how to install the GSON module? I extracted the JAR into the following folder which was in my classpath:

    C:\Program Files\Java\jdk1.6.0_07\lib
    

    ..but when i type:

    import com.google.gson.Gson;
    import com.google.gson.GsonBuilder;
    

    I still get a module not found error.

    What am I doing wrong?

    Thanks.

    解决方案

    1. You should not extract the JAR.
    2. You should not put 3rd party libraries in JDK/lib.

    You need to specify it in the classpath using -cp or -classpath argument. E.g.

    java -cp .;/path/to/gson.jar com.example.MyClass
    

    To save the time in typing it everytime, use a .bat file to execute it.

    If you're actually using an IDE like Eclipse, then you can also just rightclick the Java project, choose Build Path and then add it as new Library. Eclipse will then automatically take it in both the compiletime and runtime classpath.

    这篇关于如何在Java中安装GSON模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆