So I am running a hibernate Project in intellij but since I added a module-info hibernate isn't finding the config.
enter image description here
As you can see above the config is in resources where it's supposed to be in a maven project.
Removing the module-info doesnt change anything.
This is my module-info:
module ProjektRechnungsprogramm {
requires java.persistence;
requires java.sql;
requires org.hibernate.orm.core;
requires java.naming;
requires net.bytebuddy;
requires org.hibernate.commons.annotations;}
Even if I try getClass.getResource("hibernate.cfg.xml") it is returning null.
You have placed your config in utils directory so get resource using
getClass.getResource("Utils/hibernate.cfg.xml")
Related
I have trouble to use the module java.smartcardio. In my understanding I just just create a module-info.java and add
module apdu {
requires java.smartcardio;
}
I placed this file directly in the package. But this does not resolve my ``... cannot be resolved to a type`. Also
module com.test.bla.xxx.apdu {
requires java.smartcardio;
}
did not work.
Am I missing a setup step or something? Before now we did not use the module system yet.
Using javax.xml.transform.stream.StreamSource in a very simple program.
Using Eclipse and Java 13.
Configured Java Build Path Modulepath to contain JRE SystemLibrary [JavaSE-13] .
I have added requires java.base; to module-info.java.
But still: Eclipse cannot compile that class:
The type javax.xml.transform.stream.StreamSource is not accessible
What do I miss?
As documented by StreamSource, that class is in the java.xml module:
Which means to use StreamSource in your module you need the following module-info:
module <your-module-name> {
requires java.xml;
// other requires, exports, opens, uses, and provides directives (as needed)
}
Note you don't need to include requires java.base; as that module is implicitly required by every module, similar to how you don't need to import classes from the java.lang package.
I have an application, that uses Spring Boot and Spring Data JPA with annotation-only based configuration for its persistence layer. I've started migrating this application to the latest Spring Boot version (2.1.x) along with Java (OpenJDK) 11. After configuring the module descriptors, the application starts up, but when Spring reaches the point where it wants to build up the persistence layer, the application stops with the following exception:
Caused by: javax.persistence.PersistenceException: Unable to resolve persistence unit root URL
at spring.orm#5.1.2.RELEASE/org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.determineDefaultPersistenceUnitRootUrl(DefaultPersistenceUnitManager.java:640)
at spring.orm#5.1.2.RELEASE/org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.preparePersistenceUnitInfos(DefaultPersistenceUnitManager.java:462)
at spring.orm#5.1.2.RELEASE/org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.afterPropertiesSet(DefaultPersistenceUnitManager.java:443)
at spring.orm#5.1.2.RELEASE/org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:328)
at spring.beans#5.1.2.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1804)
at spring.beans#5.1.2.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1741)
... 16 common frames omitted
Caused by: java.io.FileNotFoundException: class path resource [] cannot be resolved to URL because it does not exist
at spring.core#5.1.2.RELEASE/org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:195)
at spring.orm#5.1.2.RELEASE/org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.determineDefaultPersistenceUnitRootUrl(DefaultPersistenceUnitManager.java:636)
... 21 common frames omitted
This issue only happens when I try to run the application in IntelliJ IDEA, which starts the JVM by configuring the module path, instead of the classpath (as expected). When I try to run the application packaged as executable jar, the issue is gone, but as I noticed, the module descriptors are basically ignored when the application runs from the executable jar...
What I've managed to discover is that the org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager finds the entities, and also stores them in a persistence unit, but after that, it tries to determine the persistence unit root URL, and that's the point where the failure occurs. Without the module descriptors, the application has a classpath, and that's enough for the DefaultPersistenceUnitManager, it will use the target directory (running from IDEA) or the persistence Maven module's JAR (running from executable JAR).
I assume there's something I'm missing from the module descriptor, so just for the reference, it looks like this:
open module leaflet.app.backend.persistence {
requires java.persistence;
requires java.validation;
requires org.apache.commons.lang3;
requires org.hibernate.orm.core;
requires spring.beans;
requires spring.context;
requires spring.data.commons;
requires spring.data.jpa;
requires spring.tx;
exports hu.psprog.leaflet.persistence.dao;
exports hu.psprog.leaflet.persistence.entity;
exports hu.psprog.leaflet.persistence.repository;
exports hu.psprog.leaflet.persistence.repository.specification;
}
If anyone might have something in mind about this issue, please don't hesisate to write it down - I'm basically stuck at this point. Thank you very much in advance!
I had the same error and I've managed to resolve it by adding java.xml.bind
requires java.persistence;
requires java.validation;
requires java.sql;
requires java.xml.bind;
requires spring.boot;
requires spring.boot.autoconfigure;
requires spring.beans;
requires spring.context;
requires spring.core;
requires spring.data.jpa;
requires spring.data.commons;
requires spring.tx;
requires spring.web;
requires slf4j.api;
requires lombok;
requires net.bytebuddy;
requires tomcat.embed.core;
Add following into your module-info.java:
requires net.bytebuddy;
I'm using v3.7.0 of the plugin as required and JDK 9.0.1. I have added two requires statements, each referring to a jar in the class path (automatic module). The module-info.java compiles successfully in Eclipse after I moved the jars to Modulepath. However, Maven gives me a compiler error saying one of them is missing (strangely, not the first one which is just one line before). I tried to check the automatic module name but I get an error from the commands just for this jar. What does this error mean and how do I fix it so that I can discover the proper module name?
I replaced my username in the output below. The jar in question does use a ServiceLoader but is not compiled with Java 9.
computerName:Commander-java username$ jar --file=/Users/username/.m2/repository/com/username/rcf/1.0/rcf-1.0.jar --describe-module
Unable to derive module descriptor for: /Users/username/.m2/repository/com/username/rcf/1.0/rcf-1.0.jar
Provider class com.username.rcf.server.TestCmdChain not in module
computerName:Commander-java username$ java -p /Users/username/.m2/repository/com/username/rcf/1.0/rcf-1.0.jar --list-modules
Error occurred during initialization of boot layer
java.lang.module.FindException: Unable to derive module descriptor for /Users/username/.m2/repository/com/username/rcf/1.0/rcf-1.0.jar
Caused by: java.lang.module.InvalidModuleDescriptorException: Provider class com.username.rcf.server.TestCmdChain not in module
The answer in How to deal with java keywords in auto generated module names in Java 9? has a different error related to using a Java identifier in the module name. The automatic jar name for my module should just be rcf since the jar name is rcf-1.0.jar. The error I'm getting is different also.
While deriving module description the contents of any
META-INF/services configuration files are mapped to provides
declarations.
The packages scanned for the services are the ones containing class files.
Also, the package name for individual classes is derived from their fully qualified name. From the shared logs com.username.rcf.server shall be the expected package name for the service to be provided and this shall turn into
provides x.y.z.TestCmdChainInterface with com.username.rcf.server.TestCmdChain
Seems like there is no such package com.username.rcf.server existing in your module.
I have some java9 module that uses 3rd party library that is not Java9 module, just a simple utility jar.
However, the compiler complains that it can't find a package from my utility.
What should I do in module-info.java to enable usage of my 3rd party library?
You can use your library as an automatic module. An automatic module is a module that doesn't have a module descriptor (i.e. module-info.class).
But what name do you need to specify to refer to an automatic module? The name of the automatic module is derived from the JAR name (unless this JAR contains an Automatic-Module-Name attribute). The full rule is quite long (see Javadoc for ModuleFinder.of), so for simplicity, you just have to drop the version from its name and then replace all non-alphanumeric characters with dots (.).
For example, if you want to use foo-bar-1.2.3-SNAPSHOT.jar, you need to add the following line to module-info.java:
module <name> {
requires foo.bar;
}
To put it in simple steps, to use a 3rd party jar (e.g. log4j-api-2.9.1.jar below) in your module:-
Execute the descriptor command of jar tool
jar --file=/path/to/your/jar/log4j-api-2.9.1.jar --describe-module
This would provide you an output similar to
No module descriptor found. Derived automatic module.
log4j.api#2.9.1 automatic
In your module descriptor file, declare a requires to that module name as:-
module your.module {
requires log4j.api;
}
That's it.