首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Maven工件Java 9迁移

Maven工件Java 9迁移
EN

Stack Overflow用户
提问于 2017-09-24 23:54:11
回答 1查看 396关注 0票数 0

我在个人关系maven存储库中有几个工件,它们都在Java 8项目上工作得很好。当与Java 9 maven项目一起使用时,这些工件都无法工作:

代码语言:javascript
复制
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,但没有成功。

我要找的是:

  • 很好的资源来帮助我理解我需要做什么
  • 指针去掉了我的项目结构&下面的代码

项目结构

代码语言:javascript
复制
.
├── 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

pom.xml

代码语言:javascript
复制
<?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-info.java

代码语言:javascript
复制
module adenix.response {
  requires spring.web;

  exports io.adenix.spring.util;
}

ResponseUtil.java

代码语言:javascript
复制
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);
  }
}

更新1

删除module-info.java允许它在模块名response.util下工作。这让我相信,module-info.java中缺少了一些东西。

我暂时修复了删除module-info.java,但我希望能够像spring那样选择名称。我要看看他们的v5预告片是否在任何地方公开,看看他们是如何做到的。任何帮助都是非常感谢的。

EN

回答 1

Stack Overflow用户

发布于 2017-09-25 01:41:15

您的模块在module-info.java中被称为adenix.response,因此依赖项使用者端的需求语法就变成了

requires adenix.response

下面是模块-info.java的组件

代码语言:javascript
复制
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
}

以下情况可能有助于解释模块-info.java中的组件

生产者模块-info.java

代码语言:javascript
复制
module adenix.response { // Module name
    requires spring.web; // Dependency module name

    exports io.adenix.spring.util; // Package name which is exported
}

消费者模块-info.java

代码语言:javascript
复制
module some.module {
    requires adenix.response; // Module name of Producer
}

如何更改名称:

生产者模块-info.java

代码语言:javascript
复制
module my.awesome.module { // Module name
    requires spring.web; // Dependency

    exports io.adenix.spring.util; // Package name which is exported
}

消费者模块-info.java

代码语言:javascript
复制
module some.module {
    requires my.awesome.module; // Module name of Producer
}

您可以参考下列资源,这些资源可能会有所帮助:

  1. 斯蒂芬·柯尔伯恩的博客:Java 9模块- JPMS基础
  2. 探索Java 9
  3. 真实世界Java 9
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46395937

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档