简体   繁体   English

如何在Java项目中使用Java EE API?

[英]How can I use an Java EE API in a Java project?

I'm reading about the Java API for Json Processing, specified in ths site. 我正在阅读该网站中指定的Json Processing Java API However, when I try to test such code like: 但是,当我尝试测试这样的代码时:

JsonReader reader = Json.createReader(new FileInputStream(...));

I can't, cause neither JsonReader class or Json class can't be imported from nowhere. 我不能,因为JsonReader类或Json类都无法从无处导入。 I only get some JsonParser class which is imported from sun.org.mozilla.javascript.internal.json.JsonParser but obviously it isn't what I'm trying to get. 我只得到一些从sun.org.mozilla.javascript.internal.json.JsonParser导入的JsonParser类,但显然它不是我想要得到的。

I have Java EE installed and I'm working with the Java EE version of Netbeans. 我安装了Java EE,并且正在使用Netbeans的Java EE版本。 How can I seize these features? 我怎样才能抓住这些功能?

Here is the download page for the reference implementation jar of JSR-000353 这是JSR-000353参考实现jar的下载页面

https://java.net/projects/jsonp/downloads/directory/ri https://java.net/projects/jsonp/downloads/directory/ri

If you are using JSON I recommend the Jackson JSON library. 如果您使用的是JSON,我推荐使用Jackson JSON库。

http://wiki.fasterxml.com/JacksonHome http://wiki.fasterxml.com/JacksonHome

The jar files can be found here: jar文件可以在这里找到:

http://wiki.fasterxml.com/JacksonDownload http://wiki.fasterxml.com/JacksonDownload

For further information on the difference in implementations please see this question Differentiating the Jersey, Jackson, and JaxB APIs 有关实现差异的更多信息,请参阅此问题区分Jersey,Jackson和JaxB API

JSR 353 was released along with the Java EE 7 platform. JSR 353与Java EE 7平台一起发布。 JsonObject and JsonReader API can be used in two different ways: JsonObject和JsonReader API可以以两种不同的方式使用:

  • Use a Java EE 7 compliant application server, such as GlassFish 4 . 使用符合Java EE 7的应用程序服务器,例如GlassFish 4 In this case, the API is built in to the runtime and will be resolved correctly for you. 在这种情况下,API内置于运行时,将为您正确解析。 You can use NetBeans, Eclipse or IntelliJ and if the server runtime is configured properly then it just works. 您可以使用NetBeans,Eclipse或IntelliJ,如果服务器运行时配置正确,那么它就可以正常工作。

  • Alternatively, you can download the Reference Implementation from http://jcp.org/aboutJava/communityprocess/final/jsr353/index.html and integrate wit your application or container of your choice. 或者,您可以从http://jcp.org/aboutJava/communityprocess/final/jsr353/index.html下载参考实现,并与您选择的应用程序或容器集成。

A good set of samples for using this API are available at https://github.com/arun-gupta/javaee7-samples/tree/master/json . 有关使用此API的一组示例,请访问https://github.com/arun-gupta/javaee7-samples/tree/master/json

To use JSON Processing in a Maven project you can use the following Maven coordinates: 要在Maven项目中使用JSON处理 ,您可以使用以下Maven坐标:

    <dependency>
        <groupId>org.glassfish</groupId>
        <artifactId>javax.json</artifactId>
        <version>1.1</version>
        <scope>provided</scope>
    </dependency>

Or to include all of Java EE 8 add the following coordinates: 或者包括所有Java EE 8添加以下坐标:

    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>1.8</version>
        <scope>provided</scope>
    </dependency>

JSON Processing 1.1 includes new JSON Pointer , JSON Patch and JSON Merge . JSON Processing 1.1包括新的JSON指针JSON补丁JSON合并

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

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