我试图用java 9编译我的应用程序,它失败了因为native2ascii可执行文件不存在.是否已在Java 9中删除?有没有其他工具可以做同样的事情?
我正在寻找Collectors.toSetjdk-8下的实现,并且几乎看到了显而易见的事情:
public static <T> Collector<T, ?, Set<T>> toSet() {
return new CollectorImpl<>(
(Supplier<Set<T>>) HashSet::new,
Set::add,
(left, right) -> { left.addAll(right); return left; }, // combiner
CH_UNORDERED_ID);
Run Code Online (Sandbox Code Playgroud)
看combiner一下; 这已经在这里讨论过,但想法是这样的a combiner folds from the second argument into the first.这显然发生在这里.
但后来我调查了jdk-9实现并看到了这个:
public static <T> Collector<T, ?, Set<T>> toSet() {
return new CollectorImpl<>(
(Supplier<Set<T>>) HashSet::new,
Set::add,
(left, right) -> {
if (left.size() < right.size()) {
right.addAll(left); return right;
} else {
left.addAll(right); return left; …Run Code Online (Sandbox Code Playgroud) 这个应用程序出了什么问题.我认为classpath jar和模块jar的混合是有效的.对于没有明确模块信息的所有罐子成为自动模块?当我删除我的module-info.java时,它可以工作.因为IDEA在这种情况下使用了类路径.
Java(TM)SE运行时环境(版本9 + 176)
IntelliJ IDEA 2017.1.4
module-info.java
module test {
requires spring.boot.autoconfigure;
requires spring.boot;
}
Run Code Online (Sandbox Code Playgroud)
App.java
package com.foo.test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
的pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.foo.test</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.M2</version>
</parent>
<name>test</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.9</maven.compiler.source>
<maven.compiler.target>1.9</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/libs-milestone</url> …Run Code Online (Sandbox Code Playgroud) 根据JEP-295(http://openjdk.java.net/jeps/295)
java.base中有一些方法导致编译失败,但为什么呢?
可以理解,有人可以帮助我,以便我可以实现Openjdk AOT编译器的限制.
我有三个模块module-a,module-b和module-c.当我运行我的应用程序时,我得到以下内容:
初始化引导层时发生错误java.lang.module.ResolutionException:模块module-a和module-b导出包some.package到模块module-c
这是什么意思,考虑到module-c不导入some.package以及如何修复它?
我正在使用jdk 1.9.我想提出一个简单的ReST服务.使用maven原型创建项目:jersey-quickstart-webapp.然后我继续修改了pom.xml和web.xml.我的maven配置如下所示:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>restWebService</groupId>
<artifactId>restWebService</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>restWebService</name>
<build>
<finalName>restWebService</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<inherited>true</inherited>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.0.0.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-client -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.19.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-bundle -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-bundle</artifactId>
<version>1.19.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-server -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.19.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-core -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId> …Run Code Online (Sandbox Code Playgroud) 在Java 9中,您可以选择将源目录打包为模块,方法是添加一个module-info.java,它定义了它导出的包,以及它依赖的其他模块.
但是,一旦这样做,您必须在模块描述符中列出所有依赖项 - 并且依赖项必须本身都是模块.因此,通过扩展,如果您模块化单个源目录,则必须对公司范围内的每个源目录进行模块化.
此外,您无法在Java 8或更早版本中定义模块,这意味着除了模块化每个Java源目录之外,还必须将所有内容转换为Java 9.同时.
如果您在一个拥有大量代码的公司工作,这似乎是灾难性的,这些代码由许多不同的项目共享.
现在,我可以通过设置一堆编译器标志来解决这个问题,以避免定义模块,但这似乎是一个非常糟糕的解决方案.
我希望我错误地理解这一点?
java java-platform-module-system java-9 java-module module-info
我有一个有趣的担忧.我习惯了多模块Maven项目.现在我正在调查如何做同样的事情,但也使用Jigsaw.是的,每个Maven模块只能有一个Jigsaw模块吗?在IDE中,我无法在同一个Maven模块中创建第二个.
那么,到目前为止,是否有任何约定或解决方法如何组合模块的两面?
在Java 1.8中,我使用以下方法生成WS客户端没有问题:
wsdl2java -ant -client -d ClientDir hello_world.wsdl
Run Code Online (Sandbox Code Playgroud)
参考Apache CXF文档 http://cxf.apache.org/docs/developing-a-consumer.html
但在Java 9中,我遇到以下错误:
-Djava.endorsed.dirs=./../lib/endorsed is not supported. Endorsed standards and standalone APIs
in modular form will be supported via the concept of upgradeable modules.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Run Code Online (Sandbox Code Playgroud)
我知道这些问题的一部分已经在如何替换Java 9中的已签名目录中进行了介绍?然而,@ nullpointer提出的解决方案对于像我这样的Java初学者来说还不够明确.
任何人都可以用"简单的方式"解释如何在不返回Java 1.8的情况下生成ws客户端存根?
谢谢
我已添加requires transitive java.activation到我的module-info.java,但java-10正在给我一个编译器警告module-info.java: module java.activation has been deprecated and marked for removal,尽管我已经在我的Maven 上添加了对com.sun.activation:javax.activation:1.2.0(Automatic-Module-Name: java.activation)的依赖pom.xml.
我可以通过添加@SuppressWarnings("removal")到我的模块声明来解决这个问题,但我从不喜欢抑制我可以修复的警告.还有什么我可以做的事情来与编译器沟通我打算依赖第三方jar而不是该模块的内置/弃用版本?
非常感谢!
java-9 ×10
java ×8
java-module ×3
java-platform-module-system ×3
cxf ×1
endorsed ×1
java-10 ×1
java-8 ×1
java-stream ×1
jax-rs ×1
jersey ×1
jvm ×1
maven ×1
module-info ×1
rest ×1
spring ×1