我尝试了很多变种,但无法完成这项工作.一个例子(孩子pom.xml):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<configuration>
<filesets>
<fileset>
<directory>target</directory>
<useDefaultExcludes>true</useDefaultExcludes>
<excludes>
<exclude>myFolder</exclude>
</excludes>
</fileset>
</filesets>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
Maven总是试图删除我的文件夹.为什么?
是否可以在模块路径上拥有2个具有完全相同名称(但内容略有不同)的模块?
据我所知,Java 9编译器并没有抱怨它.我有2个模块声明如下:
module com.dj.helper {
exports com.dj.helper;
}
Run Code Online (Sandbox Code Playgroud)
两者都包含com.dj.helper包,但在包内的内容是不同的.然后在我的主应用程序中,我想要导入此模块:
module com.dj {
requires com.dj.helper;
}
Run Code Online (Sandbox Code Playgroud)
具有相同名称的两个模块都在我的模块路径上.
我希望在编译我的com.dj模块时,编译器会抱怨同一模块存在两次,但事实并非如此.这是否有效地意味着您可以在模块路径上拥有相同jar的2个版本,而Java将不知道使用哪个版本?
当我在SpringBoot代码中引入java 9模块时,我得到了大量的"拆分包"错误.它们无处不在,例如:
Error:java: the unnamed module reads package org.bson.types from both bson and mongodb.driver
Error:java: the unnamed module reads package org.bson.io from both bson and mongodb.driver
Error:java: the unnamed module reads package org.bson from both bson and mongodb.driver
Error:java: the unnamed module reads package com.mongodb.client.model from both mongodb.driver.core and mongodb.driver
Error:java: the unnamed module reads package com.mongodb.client from both mongodb.driver.core and mongodb.driver
Error:java: the unnamed module reads package com.mongodb from both mongodb.driver.core and mongodb.driver
Error:java: the unnamed module reads package …Run Code Online (Sandbox Code Playgroud) 我有一个使用Java 8的项目.
到目前为止,在pom中我们将源版本和目标版本指定为1.8:
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
Run Code Online (Sandbox Code Playgroud)
我们想利用Java 9+的"-release"选项并添加以下内容:
<maven.compiler.release>1.8</maven.compiler.release>
Run Code Online (Sandbox Code Playgroud)
但现在我们收到以下错误:
Fatal error compiling: release version 1.8 not supported
Run Code Online (Sandbox Code Playgroud)
我们使用maven 3.5.3,版本3.8.0和Java 10中的maven-compiler-plugin来编译项目.
这有什么不对?
我按照步骤创建了 HelloWorld 示例,但它没有运行。它给出了以下错误:
启动层初始化时出错 java.lang.module.FindException: Error reading module: F:\Develop\eclipse\HelloWorld\bin Caused by: java.lang.module.InvalidModuleDescriptorException: HelloWorld.class found in top-level directory (模块中不允许使用未命名的包)”
我编写了以下HttpClient代码,但它没有导致将Authorization标头发送到服务器:
public static void main(String[] args) {
var client = HttpClient.newBuilder()
.authenticator(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("username", "password".toCharArray());
}
})
.version(HttpClient.Version.HTTP_1_1)
.build();
var request = HttpRequest.newBuilder()
.uri("https://service-that-needs-auth.example/")
.build();
client.sendAsync(request, HttpResponse.BodyHandlers.ofString())
.thenApply(HttpResponse::body)
.thenAccept(System.out::println)
.join();
}
Run Code Online (Sandbox Code Playgroud)
我从我正在调用的服务中收到HTTP 401错误.就我而言,它是Atlassian Jira Cloud API.
我已经确认我的getPasswordAuthentication()方法没有被HttpClient调用.
为什么它不起作用,我该怎么做呢?
我发现了一个关于 peek 方法的 Java 8 Stream API 的测验,如下所示
Arrays.asList("Fred", "Jim", "Sheila")
.stream()
.peek(System.out::println)
.allMatch(s -> s.startsWith("F"));
Run Code Online (Sandbox Code Playgroud)
输出是
Fred
Jim
Run Code Online (Sandbox Code Playgroud)
我很困惑这个流是如何工作的?我的预期结果应该是
Fred
Jim
Sheila
Run Code Online (Sandbox Code Playgroud)
peek() 方法是一个中间操作,它处理 Stream 中的每个元素。谁能给我解释一下。
我希望 Java 14 记录实际上比类似的数据类使用更少的内存。
他们或内存使用相同吗?
在 jlink:ed 应用程序中使用记录(预览功能 java-14),在使用选项时会出现以下错误:
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
java.lang.ClassFormatError: Invalid constant pool index 11 for name in Record attribute in class file
myproj/MyClass$MyRecord
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(Unknown Source)
at java.base/java.lang.ClassLoader.defineClass(Unknown Source)
Run Code Online (Sandbox Code Playgroud) 希望records在gradle构建中使用Java 14 ,但我得到:
thufir@dur:~/NetBeansProjects/FileWatcherHandler$
thufir@dur:~/NetBeansProjects/FileWatcherHandler$ gradle clean build
> Task :compileJava FAILED
/home/thufir/NetBeansProjects/FileWatcherHandler/src/main/java/net/bounceme/dur/files/FXOrder.java:3: error: records are a preview feature and are disabled by default.
public record FXOrder(int units) {}
^
(use --enable-preview to enable records)
1 error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info …Run Code Online (Sandbox Code Playgroud) java ×9
java-14 ×3
java-module ×3
java-8 ×2
java-9 ×2
java-record ×2
maven ×2
eclipse ×1
gradle ×1
http ×1
java-11 ×1
java-stream ×1
javac ×1
jlink ×1
module-info ×1
spring ×1
spring-boot ×1