我在个人nexus maven存储库中有一些工件,它们在Java 8项目中都很有用。与Java 9 maven项目一起使用时,这些工件都无法工作:
Library Maven: io.adenix.spring.util:response-util:2.0.0.M1-SNAPSHOT has broken classes path:
/Users/adenix/.m2/repository/io/adenix/spring/util/response-util/2.0.0.M1-SNAPSHOT/response-util-2.0.0.M1-SNAPSHOT.jar
我已经烧掉了一天中最好的部分,试图在线查找资源,解释如何迁移我的工件以使用Java 9但没有成功。
我正在寻找:
.
├── pom.xml
├── spring-response-util.iml
└── src
├── main
│ └── java
│ ├── io
│ │ └── adenix
│ │ └── spring
│ │ └── util
│ │ └── ResponseUtil.java
│ └── module-info.java
└── test
└── java
└── io
└── adenix
└── spring
└── util
└── ResponseUtilTests.java
<?xml version="1.0" encoding="UTF-8"?>
<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>io.adenix.spring.util</groupId>
<artifactId>response-util</artifactId>
<version>2.0.0.RC1-SNAPSHOT</version>
<organization>
<!-- OMITTED: PERSONAL INFO -->
</organization>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- TODO: MOVE TO RELEASE ONCE ITS OUT -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.0.0.RC3</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-jcl</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<distributionManagement>
<!-- OMITTED: PERSONAL REPO -->
</distributionManagement>
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<!-- OMITTED: PERSONAL REPO -->
</repositories>
</project>
module adenix.response {
requires spring.web;
exports io.adenix.spring.util;
}
package io.adenix.spring.util;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
/**
* This class consists exclusively of static methods that create <tt>{@link ResponseEntity}</tt>
* objects. It contains polymorphic algorithms that accept parameters to be wrapped by
* <tt>{@link ResponseEntity}</tt>.
*
* <p>The methods of this class all throw a <tt>{@link NullPointerException}</tt>
* if the parameters provided to them are null.
*
* @author Austin Nicholas
* @see ResponseEntity
* @see HttpStatus
* @since 1.8
*/
public class ResponseUtil {
/**
* Forms a <tt>{@link ResponseEntity}</tt> containing no content with a {@link HttpStatus} of 204 No Content.
*
* @return a new <tt>{@link ResponseEntity}</tt> containing 204 No Content status
*/
public static ResponseEntity<?> respond() {
return new ResponseEntity<>(null, HttpStatus.NO_CONTENT);
}
/**
* Forms a <tt>{@link ResponseEntity}</tt> containing no content with a custom {@link HttpStatus}.
*
* @param status <tt>{@link HttpStatus}</tt> to be returned with the <tt>{@link ResponseEntity}</tt>
* @return a new <tt>{@link ResponseEntity}</tt> containing the <tt>status</tt>
*/
public static ResponseEntity<?> respond(HttpStatus status) {
if(status == null)
throw new NullPointerException();
return new ResponseEntity<>(null, status);
}
/**
* Forms a <tt>{@link ResponseEntity}</tt> containing an object with a {@link HttpStatus} of 200 Ok.
*
* @param response object to be return in the <tt>{@link ResponseEntity}</tt>
* @param <T> input type of response to be used as the output type of <tt>{@link ResponseEntity}</tt>
* @return a new <tt>{@link ResponseEntity}</tt> containing the <tt>response</tt>
* object and 200 Ok status
*/
public static <T> ResponseEntity<T> respond(T response) {
if(response == null)
throw new NullPointerException();
return new ResponseEntity<>(response, HttpStatus.OK);
}
/**
* Forms a <tt>{@link ResponseEntity}</tt> containing an object with a custom {@link HttpStatus}.
*
* @param response object to be return in the <tt>{@link ResponseEntity}</tt>
* @param status <tt>{@link HttpStatus}</tt> to be returned with the response
* @param <T> input type of response to be used as the output type of <tt>{@link ResponseEntity}</tt>
* @return a new <tt>{@link ResponseEntity}</tt> containing the <tt>response</tt>
* object and the <tt>status</tt>
*/
public static <T> ResponseEntity<T> respond(T response, HttpStatus status) {
if(response == null || status == null)
throw new NullPointerException();
return new ResponseEntity<>(response, status);
}
}
删除module-info.java
允许它在模块名称response.util
下工作。这让我相信module-info.java
中缺少某些内容。
我暂时解决了删除module-info.java
的问题,但我希望能够像春天一样选择名称。我将看看他们的v5预发布是否公开,如果在任何地方公开,看看他们是如何做到的。任何帮助表示赞赏。
答案 0 :(得分:1)
您的模块在module-info.java中被称为 adenix.response ,因此依赖性使用方的需要语法变为
requires adenix.response
以下是module-info.java的组件
module module.name // *module name* not package name of current module. This is the name other modules will add under requires
{
requires other.module.name; // *module name* of another module current module is dependent on
exports some.package; // *package* which current module is going to export
}
以下案例可能有助于解释module-info.java中的组件
制片人 module-info.java
module adenix.response { // Module name
requires spring.web; // Dependency module name
exports io.adenix.spring.util; // Package name which is exported
}
消费者 module-info.java
module some.module {
requires adenix.response; // Module name of Producer
}
如何更改名称:
制片人 module-info.java
module my.awesome.module { // Module name
requires spring.web; // Dependency
exports io.adenix.spring.util; // Package name which is exported
}
消费者 module-info.java
module some.module {
requires my.awesome.module; // Module name of Producer
}
您可以参考以下可能有用的资源: