小编Pen*_*ang的帖子

为什么我的Java9模块服务不起作用?

---------------------------------------------
package org.zpf.service;
public interface Services {
    void test();
}
module org.zpf.service.Services {
    exports org.zpf.service;
}
---------------------------------------------
package org.zpf.impl;
import org.zpf.service.Services;

public class Impl implements Services {
@Override
public void test() {
    System.out.println("Impl-1");
 }
}

module org.zpf.impl.Impl {
    requires org.zpf.service.Services;
    provides org.zpf.service.Services with org.zpf.impl.Impl;
}
----------------------------------------------
public class Demo {
   public static void main(String[] args) {
      ServiceLoader.load(Services.class).forEach(Services::test);
   }
}

module org.zpf.demo.Demo {
    requires org.zpf.service.Services;
    uses org.zpf.service.Services;
}
Run Code Online (Sandbox Code Playgroud)

我使用IntelliJ IDEA运行此代码,但看起来子模块未运行.以下是程序的输出:

/Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home/bin/java "-javaagent:/Applications/IntelliJ IDEA 2018.3.app/Contents/lib/idea_rt.jar=61434:/Applications/IntelliJ IDEA 2018.3.app/Contents/bin" -Dfile.encoding=UTF-8 -p /Users/tubetrue01/IDEA/Test/Demo/target/classes:/Users/tubetrue01/IDEA/Test/Services/target/classes -m org.zpf.demo.Demo/org.zpf.demo.Demo …
Run Code Online (Sandbox Code Playgroud)

java service java-9 java-module module-path

5
推荐指数
1
解决办法
165
查看次数

标签 统计

java ×1

java-9 ×1

java-module ×1

module-path ×1

service ×1