这个应用程序出了什么问题.我认为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) public static long checkedAdd(long a, long b) {
long result = a + b;
checkNoOverflow((a ^ b) < 0 | (a ^ result) >= 0);
return result;
}
Run Code Online (Sandbox Code Playgroud)
我感兴趣为什么布尔逻辑| 在这里使用.为什么不使用条件短路||?
这是我正在运行的代码:
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
public class Main {
public static void main(String[] args) throws Exception {
String filePath = "D:/temp/file";
RandomAccessFile file = new RandomAccessFile(filePath, "rw");
try {
MappedByteBuffer buffer = file.getChannel().map(FileChannel.MapMode.READ_WRITE, 0, 128);
// Do something
buffer.putInt(4);
} finally {
file.close();
System.out.println("File closed");
}
System.out.println("Press any key...");
System.in.read();
System.out.println("Finished");
}
}
Run Code Online (Sandbox Code Playgroud)
在按下某个键之前,我正在尝试在FAR Manager中手动删除该文件.但FAR说该文件被锁定:
The process cannot access the file because it is being used by another process.
Cannot delete the file
D:\temp\file
Object is being opened …Run Code Online (Sandbox Code Playgroud) 我想合并两个列表:
import scalaz.syntax.align._
import scalaz.std.list._
import scalaz.std.anyVal._
List(1, 2, 3).merge(List(4, 5, 6, 7)) // Evaluates to List(5, 7, 9, 7)
Run Code Online (Sandbox Code Playgroud)
这隐含地使用标准加法monoid.如果我想使用乘法幺半群怎么办?在Scalaz中这样做的惯用方法是什么?
我有一个字符串列表,我想在其中编写文件中的不同字符串集,以及将其转换为UUID并将其存储为另一个变量.是否可以使用Java 8 lambdas以及如何使用?
我要两个收藏家的原因是避免将它运行到第二个循环中.
使用9-ea + 171,Maven 3.5.0
我正在用这个module-info.java编译一个项目:
module org.project {
}
Run Code Online (Sandbox Code Playgroud)
但它失败了一个神秘的错误:
[ERROR] Failed to parse module-info:
[ERROR] With qdox: null
(...)
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:testCompile (default-testCompile) on project rli-stubs: Execution default-testCompile of goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:testCompile failed: Failed to parse module-info -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:testCompile (default-testCompile) on project rli-stubs: Execution default-testCompile of goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:testCompile failed: Failed to parse module-info
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)
at …Run Code Online (Sandbox Code Playgroud) 现在JDK 9正式发布,我已经升级了Mac OSX以运行Java SE Development Kit 9.
Android Device Monitor(/Library/Android/sdk/tools/monitor)不再有效.记录在这里:
!ENTRY org.eclipse.osgi 4 0 2017-09-24 13:30:55.822
`enter code here`!MESSAGE Application error
!STACK 1
java.lang.IllegalStateException: Unable to acquire application service. Ensure that the org.eclipse.core.runtime bundle is resolved and started (see config.ini).
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:74)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
Run Code Online (Sandbox Code Playgroud)
我已经能够通过添加修复Eclipse Oxygen的类似问题
--add-modules=java.se.ee
Run Code Online (Sandbox Code Playgroud)
在eclipse.ini,作为解释在这个SO回答
霓虹:如何在jdk9上运行?.这修复了100%的Eclipse问题,所以现在我可以毫无问题地运行eclipse,但Android设备监视器仍未运行.
我已经尝试了在启动Eclipse时没有成功的解决方案"无法获取应用程序服务"错误.
还有其他必须配置的东西吗?
该程序基于JDK 9(JPMS),使用IDE(Intellij)时使用一些第三方jar,如Apache(poi-3.17.jar,commons-io-2.6.jar)和HikariCP(HikariCP-3.1.0.jar) ) 我“需要”它们并且程序运行良好。当我尝试使用 java9 'jlink' 获取自定义 JRE 时,我得到以下信息:
/out$ jlink --module-path production --add-modules
studyModule,java.base,java.datatransfer,java.desktop,java.logging,
java.scripting,java.sql,java.xml,java.prefs,javafx.base,
javafx.controls,javafx.fxml,javafx.graphics,javafx.media,
javafx.swing,javafx.web,jdk.jsobject,jdk.xml.dom,jdk.unsupported
--output studyJre
Error: module-info.class not found for com.zaxxer.hikari module
/out$ jlink --module-path production --add-modules
studyModule,java.base,java.datatransfer,java.desktop,java.logging,
java.scripting,java.sql,java.xml,java.prefs,javafx.base,
javafx.controls,javafx.fxml,javafx.graphics,javafx.media,
javafx.swing,javafx.web,jdk.jsobject,jdk.xml.dom,jdk.unsupported
--output studyJre
Error: module-info.class not found for poi module
Run Code Online (Sandbox Code Playgroud)
问题是:为什么那些带有 IDE 的包可以正常工作?如果它们没有被模块化,那么也不应该在 IDE 中工作。
PS:在使用 jlink 时,我将这些 jars 添加到“root”文件夹中。
我有一个对象流,我想对其进行自然排序,但也强制其中一个成员始终位于第一位。
例如:
List<String> result = Stream.of("a", "s", "d", "f")
.sorted(Comparator.comparing((String s) -> !s.equals("d"))
.thenComparing(Comparator.naturalOrder()))
.collect(toList());
System.out.println(result);
Run Code Online (Sandbox Code Playgroud)
这会产生
[d, a, f, s]
Run Code Online (Sandbox Code Playgroud)
也就是说,按字母顺序排列,但以“d”开头。
我注意到我还可以使用多个.sorted(...)调用来编写此内容:
List<String> result = Stream.of("a", "s", "d", "f")
.sorted()
.sorted(Comparator.comparing(s -> !s.equals("d")))
.collect(toList());
System.out.println(result);
Run Code Online (Sandbox Code Playgroud)
这会产生相同的结果,并且在我看来更具可读性。
但是,我没有看到其他人这样做的例子。
此外,IntelliJ IDEA 将第一次.sorted()调用标记为冗余。它说“随后的‘排序’调用使排序变得毫无用处”。
这显然是不正确的,因为删除调用会将输出更改为
[d, a, s, f]
Run Code Online (Sandbox Code Playgroud)
所以我的问题是:.sorted(...)对 Stream 的多次调用是否定义了行为,还是我只是运气好?
换句话说,这是.sorted()我可以依赖的受支持的使用,还是它只是现在才起作用,并且可能在将来的某个 Java 版本中停止工作?
在回答这个问题后,我在 Github 上发布了 Java 9 模块教程 + 示例以及如何为未来用户运行:
我有以下非常简单的结构:
src
? module-info.java
?
????moduleA
????pack1
Main.java
Run Code Online (Sandbox Code Playgroud)
module-info.java :
module moduleA {
}
Run Code Online (Sandbox Code Playgroud)
Main.java:
package moduleA.pack1;
public class Main{
public static void main(String[] args){
System.out.println("Hello Java 11");
}
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试编译然后运行这个非常简单的模块化 java 应用程序。
所以从我运行的 cmd 开始:
编译
javac --module-source-path src -d out -m moduleA
Run Code Online (Sandbox Code Playgroud)
跑
java --module-path out -m moduleA/pack1.Main
Run Code Online (Sandbox Code Playgroud)

从 IntelliJ 开始,它的作用就像魅力一样,我不知道它背后有什么魔力。
我做错了什么?
java ×9
java-9 ×5
java-8 ×2
java-stream ×2
apache-poi ×1
collectors ×1
eclipse ×1
guava ×1
hikaricp ×1
java-11 ×1
java-module ×1
java-platform-module-system ×1
jlink ×1
lambda ×1
long-integer ×1
maven-3 ×1
modularity ×1
scala ×1
scalaz ×1
spring ×1