java-module

How many unnamed modules are created in Java 9?

老子叫甜甜 提交于 2019-12-01 05:17:23
I am trying to understand how JPMS works. From here The classpath is not completely gone yet. All JARs (modular or not) and classes on the classpath will be contained in the Unnamed Module. Similar to automatic modules, it exports all packages and reads all other modules. But it does not have a name, obviously. For that reason, it cannot be required and read by named application modules. The unnamed module in turn can access all other modules. Please, note ...on the classpath will be contained in the Unnamed Module . Module is singular. From here For compatibility, all code on the classpath is

Module javafx.controls not found in Java 9

这一生的挚爱 提交于 2019-12-01 05:13:30
I have two JPMS module in two files: modulea.jar and moduleb.jar . Modulea requires javafx.controls module. I need to use these modules in new layer, so I do: ModuleFinder finder = ModuleFinder.of(modAPath, modBPath); ModuleLayer parent = ModuleLayer.boot(); Configuration cf = parent.configuration().resolveAndBind(finder, ModuleFinder.of(), new HashSet<>()); ClassLoader scl = ClassLoader.getSystemClassLoader(); ModuleLayer newLayer = parent.defineModulesWithOneLoader(cf, scl); I thought that JDK modules will be loaded automatically but I get Exception in thread "main" java.lang.module

How to get ResourceBundle from another Module in Java 9?

杀马特。学长 韩版系。学妹 提交于 2019-12-01 03:45:08
问题 I have two modules: module-a and module-b. Module-a has properties file ( com/foo/texts_en.properties ). Module-a exports com.foo package. In module-b I want to get this resource. For this I do the following in module-b: Module moduleA = ClassFromModuleA.class.getModule(); ResourceBundle resourceBundle = ResourceBundle.getBundle("com/foo/texts", Locale.ENGLISH, moduleA.getClassLoader()); System.out.println("TEST :" + resourceBundle.getString(key); This is what I get: Caused by: java.util

Why is exporting the entire module not allowed?

人走茶凉 提交于 2019-12-01 03:06:55
In Java 9's module declaration there are 2 constructs: exports com.foo; And opens com.foo; Where exports grants compile-time access, while opens allows runtime access, as reflection and resources. opens has one leniency over exports that you can define the whole module as open, resulting the same as explicitly opening every package: open module com.mod { But there's no similar construct exported module com.mod { My Question : Why is it so; what decisions has been made to allow opening the whole module at once but not with exporting? A module's exports define its API, which should be

How many unnamed modules are created in Java 9?

安稳与你 提交于 2019-12-01 02:18:07
问题 I am trying to understand how JPMS works. From here The classpath is not completely gone yet. All JARs (modular or not) and classes on the classpath will be contained in the Unnamed Module. Similar to automatic modules, it exports all packages and reads all other modules. But it does not have a name, obviously. For that reason, it cannot be required and read by named application modules. The unnamed module in turn can access all other modules. Please, note ...on the classpath will be

Proper way to use Spring JAXB Marshaller with Java 9 without defining additional modules

回眸只為那壹抹淺笑 提交于 2019-12-01 00:19:12
To illustrate my issue, I created a small spring boot sample application. The purpose of the application is to create a Jaxb2Marshaller bean. @SpringBootApplication public class App implements CommandLineRunner { public static void main(String[] args) { SpringApplication.run(App.class, args); } @Bean public Jaxb2Marshaller jaxb2Marshaller() { Jaxb2Marshaller bean = new Jaxb2Marshaller(); bean.setContextPath("ch.sahits.game.helloworld"); return bean; } @Override public void run(String... args) throws Exception { System.out.println("Started up"); } } This code fails to start up with the

Can I exclude an exported package from a Java module?

血红的双手。 提交于 2019-11-30 20:26:43
Modules jta and java.sql export package javax.transaction.xa to module dom4j As you can see, both modules jta and java.sql export the same package, javax.transaction.xa . However, the package in jta has classes that I require that are not present in java.sql . I would simply not require the java.sql module, but I need java.sql.SQLException . Is it possible to prevent java.sql from exporting javax.transaction.xa ? The JTA GitHub reads the following in confirmation to what @Alan already pointed out in a comment - This standalone release of Java(TM) Java Transaction API (JTA), uses a Java

What is an open module in Java 9 and how to use it

旧巷老猫 提交于 2019-11-30 11:08:14
What is the difference between module with open keyword before and without it? For instance: open module foo { } module foo { } Michał Szewczyk In order to provide reflective access to your module, Java 9 introduced open keyword. You can create open module by using open keyword in module declaration. An open module grants reflective access to all of it's packages to other modules. For example, if you want to use some framework, that heavily relies on reflection, such as Spring, Hibernate etc, you can use this keyword, to enable reflective access for it. You can enable reflective access for

findResource(“”) returning null when module-info.java is present, why is that?

大城市里の小女人 提交于 2019-11-30 10:41:51
I'm debugging why in the presence of module-info.java in my Spring Boot application, spring-orm throws an exception during start up time. This is the exception: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/transaction/UserTransaction at spring.beans@5.0.8.RELEASE/org.springframework.beans.factory.support

Self-Contained Applications, built in Java

混江龙づ霸主 提交于 2019-11-30 06:59:40
I've watched a few online presentations that briefly mentioned self-contained applications in Java 9, but I have a question that I would like cleared up. With the new module system, you're now allowed to only include the minimum amount of code required to run your application. However, does the system that wishes to run the application still require the JRE, or is that something that can be included in the base module within the program? I suspect it's the latter, as the page ( here ) to download the newest version of Java still shows version 8_151. TL;DR - Using Java 9, is it possible to