---------------------------------------------
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;
}
私はのIntelliJ IDEAでこのコードを実行していますが、サブモジュールではありませんrunning.The以下は、プログラムの出力であるように見えます:
/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
Process finished with exit code 0
すべてを行う必要があることですモジュールことを確認してください
module org.zpf.impl // fixing the name from that of question
ModulePath上に存在します。パスに加えて、コマンドラインから、あなたが共有するようにコマンドを実行するとimpl
同じように期待されるモジュール作品。
.../jdk-11.jdk/Contents/Home/bin/java -p .../Desktop/modular/out/production/demo:.../Desktop/modular/out/production/modular:.../Desktop/modular/out/production/impl -m org.zpf.demo.Demo/org.zpf.demo.Demo
expted出力を印刷します
Impl-1
あなたには、コマンドライン(単に読みやすくするためにフォーマット)
-p /Users/tubetrue01/IDEA/Test/Demo/target/classes:
/Users/tubetrue01/IDEA/Test/Services/target/classes
以下のようなものに変更する必要があります
-p /Users/tubetrue01/IDEA/Test/Demo/target/classes:
/Users/tubetrue01/IDEA/Test/Services/target/classes:
/Users/tubetrue01/IDEA/Test/Impl/target/classes
IntelliJ IDEAは、次の手順で同じことを行うことができます。
Demo
依存関係にモジュールを>移動Impl
モジュールをして適用します。Demo
今クラスを。この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加