java-module

Implementing a (compile-time) plugin architecture without split packages

社会主义新天地 提交于 2019-12-02 13:15:08
问题 In a past question I asked how to design a system where: A class contains one or more optional methods. Optional methods are implemented by plugins that may or not may be present at compile-time. If a user invokes a method whose associated plugin is not present at compile-time, they will get a compile-time error. I provided one possible solution that works in Java 8. Unfortunately, this solution depends on the use of split packages (two modules exporting the same package) which are disallowed

Unable to resolve module using --module-source-path

只愿长相守 提交于 2019-12-02 09:42:25
问题 Following up on How to define qualified exports to unknown modules? I've posted a testcase with two modules: core and plugin . core tries to expose a package to plugin using qualified exports but the compiler complains that plugin does not exist. Following up on Alan Bateman's recommendation, I tried adding --module-source-path <path-of-plugin> --module plugin pointing from core to plugin but the compiler complains: module plugin not found in source path Why isn't the compiler able to find

Eclipse 2019-03 regarding Java modules and maven

佐手、 提交于 2019-12-02 09:12:53
问题 I am having a maven (3.6.0) project based on java 11 with the following structure (which works fine on the commandline!): src/main/java/ module-info.java /de/test/tp/TP.java src/test/java/ /de/test/tp/test/TPTests.java The module-info.java looks as following: module de.test.tp { exports de.test.tp; requires org.apache.logging.log4j; } TP.java: package de.test.tp; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; public class TP { private static final Logger

How can I test a service provider implementation module with Junit 5?

谁说我不能喝 提交于 2019-12-02 08:35:18
问题 This is my base module which needs implementations of interfaces defined in myspi package. Various providers can offer MyProvider implementations. Base module uses them via myspi.MyProvider interface implementation. module base { exports myspi; uses myspi.MyProvider; } This is my sample implementation module which provides the MyProvider implementation with MyProviderImpl module myspi.provider { provides myspi.MyProvider with myspi.provider.MyProviderImpl; } All these work fine when I load

How can I test a service provider implementation module with Junit 5?

谁都会走 提交于 2019-12-02 03:56:21
This is my base module which needs implementations of interfaces defined in myspi package. Various providers can offer MyProvider implementations. Base module uses them via myspi.MyProvider interface implementation. module base { exports myspi; uses myspi.MyProvider; } This is my sample implementation module which provides the MyProvider implementation with MyProviderImpl module myspi.provider { provides myspi.MyProvider with myspi.provider.MyProviderImpl; } All these work fine when I load the implementations in base module, with public static List<MyProvider> getMyProviders() { var

How to work with resources in Java 9 modules

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 20:29:15
I built a small (hello world style) java 9 project using gradle and the jigsaw plugin . For a junit test I tried to access some file as a resource, but classLoader.getResource(filename) is not able to locate the file. Usually you put the file as src/test/resources/foo.txt and access it as /foo.txt , but with Java 9 it looks like things changed and resources are (similar like classes) encapsulated in modules . Where exactly do I have to put the resource file for gradle to package it correctly? What is the right way to access that file afterwards in the test? What is the documentation I forgot

idea: too many module declarations found

纵饮孤独 提交于 2019-12-01 17:42:07
I want to create hello world java 9 application and start it in intellij idea. Now I have following structure: content of inner module-info.java: module my.module.Second { requires my.module.First; } content of outer module-info.java: module my.module.First { exports my.pack; } But idea complains about my project: Error:(1, 1) java: too many module declarations found I don't understand why it happens and what really wrong. So Question: My question is how to force idea to accept my hello world. P.S. From the first glance error looks obvious but I have project which I downloaded from github with

Java 9 sub-packages split across modules

久未见 提交于 2019-12-01 14:09:00
In Java 9, can I split sub-packages across modules? For example, can I have com.example.foo in one module and com.example.foo.bar in another module? This seems like a simple question, but for some reason I'm not able to find a direct answer after some searching. An authoritative reference would be appreciated. I assume I can have sibling sub-packages in different modules, e.g. com.example.foo and com.example.other . There's no such thing as a "sub-package". my.package and my.package.sub have nothing more in common than any two random packages: they just have similar names. See this answer

Compile a JDK 8 project + a JDK 9 “module-info.java” in Gradle

亡梦爱人 提交于 2019-12-01 11:09:00
I'm working on a Java library targeting JDK 8, and I'm building it in Gradle 5 using OpenJDK 11. In order to target JDK 8, I'm javac's --release option. However, I'd also like my library to be JPMS-compatible. In other words: I'd like to provide a module-info.class compiled with --release 9 (option 3 in Stephen Colebourne's scale ), while all the rest is compiled with --release 8 . MCVE build.gradle : plugins { id 'java' id 'org.javamodularity.moduleplugin' version '1.4.1' // * } repositories { mavenCentral() } dependencies { compileOnly 'org.projectlombok:lombok:1.18.6' } compileJava.options

Why do we need requires static in java-9 module system? [duplicate]

折月煮酒 提交于 2019-12-01 07:47:53
This question already has an answer here: What's the difference between requires and requires static in module declaration 2 answers Does the Java 9 Module system support optional dependencies? 1 answer I started to learn jigsaw java-9 feature and read some articles/video. I can't understand concept of optional dependencies( requires static ) quote from article : When a module needs to be compiled against types from another module but does not want to depend on it at run time, it can use a requires static clause. If foo requires static bar, the module system behaves different at compile and