Java 9没有类定义异常 [英] Java 9 no class definition exception

查看:104
本文介绍了Java 9没有类定义异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想尝试http客户端

So i want to try the http client

package com.company;

import jdk.incubator.http.HttpClient;

public class Main {

public static void main(String[] args) {
    HttpClient client =  HttpClient.newHttpClient();

  }
}

我的模块信息看起来像这样

And my module info looks like this

module com.company {
    requires jdk.incubator.httpclient;
}

但是我得到java.lang.NoClassDefFoundError: jdk/incubator/http/HttpClient

我真的不明白为什么.我的Java版本是"build 9-ea + 169",我使用的是IntelliJ idea(2017.1.3)的最新版本.我调查了答案,看来我只需要在文件中添加要求,但不适用于出于某些原因.

And I don't really understand why. My java version is "build 9-ea+ 169" and I use the latest version of IntelliJ idea (2017.1.3). I looked into this answer and it looks like I have to just add requirement into a file, but it doesn't work for some reason.

推荐答案

对我来说效果很好.

HttpClient client = HttpClient.newHttpClient();
client.executor().execute(() -> System.out.println("Here")); // prints Here

如果您说您的模块需要它,并不意味着它会被包括在内;默认情况下不包含.

If you say that your module requires it, does not mean it will be included; at it is not included by default.

这篇关于Java 9没有类定义异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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