Liquibase with Java 13: org.hibernate.boot.registry.classloading.spi.ClassLoadingException - java

Basically, I use Liquibase for most of my Java projects (at least where db migrations are needed) and it worked always on Java 8. I have a requirement now to migrate an existing project to Java 13. The project compiles with the Java 8 and also with Java 13 (see the configuration below), however, Liquibase Maven plug-in (mvn liquibase:diff) throws an ClassLoadingException:
org.hibernate.boot.registry.classloading.spi.ClassLoadingException: Unable to load class [com.mypackage.TestEntity]: Could not load requested class : com.mypackage.TestEntity
here is the plugin configuration in my POM file:
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>${liquibase.maven.plugin.version}</version>
<configuration>
<propertyFile>src/main/resources/db-migrations/liquibase/liquibase.properties</propertyFile>
<changeLogFile>src/main/resources/db-migrations/liquibase/db-changelog-master.xml</changeLogFile>
<diffChangeLogFile>${changeset.output.dir}/${timestamp} - ${desc}.xml</diffChangeLogFile>
<logging>info</logging>
</configuration>
<dependencies>
<dependency>
<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-hibernate5</artifactId>
<version>${liquibase-hibernate5.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>${springboot.version}</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>${validation-api.version}</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>${javassist.version}</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>${jaxb.api.version}</version>
</dependency>
</dependencies>
</plugin>
and the liquibase.properties:
url=jdbc:postgresql://localhost:5432/user_registrations
username=postgres
password=somepwd
driver=org.postgresql.Driver
referenceUrl=hibernate:spring:com.mypackage?dialect=org.hibernate.dialect.PostgreSQL9Dialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
As I mentioned it at the beginning, the Java 13 build doesn't work:
<maven.compiler.release>13</maven.compiler.release>
<java.version>13</java.version>
All dependencies have the latest version.
Any idea what could be an issue here? Thanks for any input...

Related

Package 'org.pmml4s.model' is declared in module with an invalid name ('pmml4s.2.10')

I'm trying to use PMML4S to make predictions from an imported model from sklearn. I have the model in an xml file that I am trying to load into java using pmml4s. I am trying to follow this. However, I am having issues getting it to work: specifically, "Package 'org.pmml4s.model' is declared in module with an invalid name ('pmml4s.2.10')" . I am using IntelliJ as my IDE. Please let me know if I can provide other information/code. Any help is appreciated!
Error is here:
import org.pmml4s.model.Model;
Dependencies:
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>18.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>18.0.2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.pmml4s</groupId>
<artifactId>pmml4s_2.10</artifactId>
<version>0.9.16</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>doctor</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>6.0.0</version>
</dependency>
</dependencies>
You used java 9 modules in your project and imported a library which was not converted to java 9 modules. Thus Java treats this library as an automatic module and derives module name from jar name. The jar name happens to be illegal.
See:
What is an automatic module?
You have 2 options:
Option 1: Dont use java9 modules
See:
Is there any need to switch to modules when migrating to Java 9 or later?
Option 2: Sanitize jar name
See:
Unable to derive module descriptor for auto generated module names in Java 9?
Scala Suffix Maven plugin looks like a tool designed precisely to solve your problem
Note that you need to require the automatic module in this approach:
How to use 3rd party library in Java9 module?

Maven build failed due to JDT dependencies - No versions available for org.osgi.service:org.osgi.service.prefs:jar:[1.1.0,1.2.0)

Today when I tried to install my maven project, I get an error due JDT dependencies and here is the report information:
Cannot resolve No versions available for org.osgi.service:org.osgi.service.prefs:jar:[1.1.0,1.2.0) within specified range.
[ERROR] Failed to execute goal on project redundantcheck:
Could not resolve dependencies for project edu.fudan.selab:redundantcheck:jar:1.0-SNAPSHOT:
Failed to collect dependencies at org.eclipse.jdt:org.eclipse.jdt.core:jar:3.20.0 ->
org.eclipse.platform:org.eclipse.core.resources:jar:3.12.0 ->
org.eclipse.platform:org.eclipse.core.expressions:jar:3.5.100 ->
org.eclipse.platform:org.eclipse.core.runtime:jar:3.12.0 ->
org.eclipse.platform:org.eclipse.equinox.preferences:jar:3.10.0 ->
org.osgi.service:org.osgi.service.prefs:jar:[1.1.0,1.2.0): No versions available for
org.osgi.service:org.osgi.service.prefs:jar:[1.1.0,1.2.0) within specified range -> [Help 1]
I tried to add 1.1.0 org.osgi.service:org.osgi.service.prefs to the project, but still can't solve this problem. To avoid dependency update, I specied almost every version of the dependencies, but still encounter this error today. Here is my pom.xml:
<dependencies>
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core</artifactId>
<version>3.20.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.core.commands</artifactId>
<version>3.9.800</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.core.contenttype -->
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.core.contenttype</artifactId>
<version>3.7.900</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.core.filesystem -->
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.core.filesystem</artifactId>
<version>1.7.700</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.core.jobs -->
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.core.jobs</artifactId>
<version>3.10.1100</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.core.resources -->
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.core.resources</artifactId>
<version>3.14.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.core.runtime -->
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.core.runtime</artifactId>
<version>3.20.100</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.equinox.common -->
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.common</artifactId>
<version>3.14.100</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.osgi -->
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.osgi</artifactId>
<version>3.16.200</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.text -->
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.text</artifactId>
<version>3.11.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.75</version>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.core.expressions</artifactId>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.app</artifactId>
<version>1.6.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.preferences</artifactId>
<version>3.9.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.registry</artifactId>
<version>3.11.0</version>
</dependency>
</dependencies>
Is there anyway to solve this problem?
EDIT: The issue is known by the project team and tracked as eclipse-equinox/equinox.bundles#54 on GitHub.
The dependency:
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.preferences</artifactId>
<version>3.10.0</version>
Which is one of your transitive dependency, references this dependency in its dependencies list:
<dependency>
<groupId>org.osgi.service</groupId>
<artifactId>org.osgi.service.prefs</artifactId>
<version>[1.1.0,1.2.0)</version>
</dependency>
Source: org.eclipse.equinox.preferences-3.10.0.pom on maven central.
It is a mistake. As Maven tells you, this does not exist:
Cannot resolve No versions available for org.osgi.service:org.osgi.service.prefs:jar:[1.1.0,1.2.0) within specified range.
It should have been:
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.prefs</artifactId>
<version>[1.1.0,1.2.0)</version>
</dependency>
Which exists (note the different groupId).
Because you are not fixing the dependencies you are consuming in your project, and because the dependencies are using version ranges, suddenly you got a new version.
By the way as beingnurd has noted, there is now the newer version 3.10.1 of org.eclipse.equinox.preferences where this wrong dependency is fixed (see org.eclipse.equinox.preferences-3.10.1.pom).
If you continue to use always the newest dependency of the compatible range, the problem will be solved for you.
Now if we take a step back:
You are trying to use following JDT version:
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core</artifactId>
<version>3.20.0</version>
</dependency>
This corresponds to the Eclipse Version 2019-12 (also called 4.14 internally).
Your problem is that the eclipse projects (org.eclipse.jdt.core and all the dependencies) are using version ranges.
If you look at the org.eclipse.jdt.core dependencies declarations:
org.eclipse.platform:org.eclipse.core.resources:[3.12.0,4.0.0)
org.eclipse.platform:org.eclipse.core.runtime:[3.13.0,4.0.0)
org.eclipse.platform:org.eclipse.core.filesystem:[1.7.0,2.0.0)
org.eclipse.platform:org.eclipse.text:[3.6.0,4.0.0)
If you don't do anything, Maven always takes the latest:
Today (June 2022) this would be:
org.eclipse.core.resources: 3.16.100
org.eclipse.core.runtime: 3.24.100
org.eclipse.core.filesystem: 1.9.300
org.eclipse.text: 3.12.0
When the library was published (December 2019) this was:
org.eclipse.core.resources: 3.13.600
org.eclipse.core.runtime: 3.17.0
org.eclipse.core.filesystem: 1.7.600
org.eclipse.text: 3.10.0
And of course this is recursive, you need to do this for all the dependencies.
Letting Maven choose always the latest is problematic:
It prevents you creating reproducible build, because the dependencies picked by maven depends from what is available on maven central on that day.
You need to solve conflicts.
You are potentially the first trying out a combination.
This is why I always use a set of projects that were released together. By the way this is also how the Eclipse project itself is doing it (by using P2 update sites and target platform).
I am publishing Maven BOM files to fix the versions: ECentral project
This is how you can do it:
<repositories>
<repository>
<id>ecentral</id>
<url>https://raw.githubusercontent.com/jmini/ecentral/HEAD/repo</url>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>fr.jmini.ecentral</groupId>
<artifactId>eclipse-platform-dependencies</artifactId>
<version>4.14</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core</artifactId>
<!-- no version needed here, because it is defined in the BOM -->
</dependency>
</dependencies>
Because I ran into this problem today too, but via plugin sub-dependency, my temporary solution is to download the regular org.osgi:org.osgi.service.prefs:jar:1.1.2 and install it in the local repository as org.osgi.service:org.osgi.service.prefs:jar:1.1.2.
You can exclude the dependency like this :
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core</artifactId>
<version>3.24.0</version>
<exclusions>
<exclusion>
<groupId>org.osgi.service</groupId>
<artifactId>org.osgi.service.prefs</artifactId>
</exclusion>
</exclusions>
so the reason for this failure is dependency
<groupId>org.osgi.service</groupId> <artifactId>org.osgi.service.prefs</artifactId>
but the group org.osgi.service doesn't exists, instead it is only org.osgi
so dependency should look
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.prefs</artifactId>
I have got the same problem today in our SpringBoot project 1.5.25 with org.hibernate:hibernate-tools:jar:5.0.6.Final
The error message as follow:
# Failed to collect dependencies at org.hibernate:hibernate-tools:jar:5.0.6.Final ->
# org.eclipse.jdt:org.eclipse.jdt.core:jar:3.12.2 ->
# org.eclipse.platform:org.eclipse.core.resources:jar:3.11.1 ->
# org.eclipse.platform:org.eclipse.core.expressions:jar:3.5.100 ->
# org.eclipse.platform:org.eclipse.core.runtime:jar:3.12.0 ->
# org.eclipse.platform:org.eclipse.equinox.preferences:jar:3.10.0 ->
# org.osgi.service:org.osgi.service.prefs:jar:[1.1.0,1.2.0): No versions available for org.osgi.service:org.osgi.service.prefs:jar:[1.1.0,1.2.0) within specified range -> [Help 1]
I use the private nexus, to resolve this problem, i added a proxy maven2 (maven-ecentral) repo pointed to https://raw.githubusercontent.com/jmini/ecentral/HEAD/repo , thanks #Jmini
then added the follow lignes in the pom.xml
<dependencyManagement>
<dependencies>
<dependency>
<groupId>fr.jmini.ecentral</groupId>
<artifactId>eclipse-platform-dependencies</artifactId>
<version>4.14</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<repositories>
<repository>
<id>ecentral</id>
<url>https://nexus.xxxx.xxx/repository/maven-ecentral/</url>
</repository>
</repositories>
Reload your project with IDEA, it should work.
Another solution is using exclusions
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-tools</artifactId>
<version>${hibernate-tools.version}</version>
<!-- exclure the old org.eclipse.platform -->
<exclusions>
<exclusion>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.preferences</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- the 3.10.1 org.eclipse.platform fixed the pb -->
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.preferences</artifactId>
<version>3.10.1</version>
</dependency>
Even I have been facing this problem since today, it was working fine till yesterday.
Finally what I found was that pom of org.eclipse.equinox.preferences:3.10.0 group id mentioned as org.osgi.service, but the artifact is located in repo1.maven.org at org/osgi, there is no service folder in it.
I changed dependency group id to org.osgi in the pom of org.eclipse.equinox.preferences and then it worked.
--EDIT--
I can see a new version of 3.10.1 added in repo which has the group id corrected to org.osgi instead of org.osgi.service
I ran into this problem with a maven plugin (net.revelc.code.formatter). We use it from another maven plugin that generates code. Since it is just a formatter for generated code, my solution was to drop the usage of the formatter plugin. Obviously I couldn't use the above solutions, because I don't want to fork the formatter code.

How to get eclipse libraries compiled on Java 8

Let me begin with the error I see and then I will explain the case followed by:
<p style="color:red">
EclipseJDTUtil.java:[3,34] cannot access org.eclipse.core.resources.IProject
bad class file: C:\Users\ram\.m2\repository\org\eclipse\platform\org.eclipse.core.resources\3.15.0\org.eclipse.core.resources-3.15.0.jar(org/eclipse/core/resources/IProject.class)
class file has wrong version 55.0, should be 52.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
</p>
My project has a dependency on org.eclipse.jdt.core library.
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core</artifactId>
<version>3.23.0</version>
</dependency>
I built my project with JRE8. I used maven plugin to point to the right version at compilation like below.
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
It has been OK all these days but suddenly from past few days, I see below error. I understand that this library is now available with source compiled on java 11 which is causing issues to my project. But, how is that possible? When the project source is at java 8, the dependencies should not be downloaded for java 11.
I am not in a position to update my whole project to new java version!
What I need is the eclipse libraries compiled on java 8. How should I get them on maven build? What configuration will make it possible?
Edit 1: (Response to Andreas comment):
#Andreas: Superb. As you pointed out correctly, it is pulling org.eclipse.core.resources: 3.15.0, as shown in the error. As you suggested I have added version for "resources" like below:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.core.resources</artifactId>
<version>3.12.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
After I maven build I see below error now.
<p style="color:red">
EclipseJDTUtil.java:[8,32] cannot access org.eclipse.core.runtime.IPath
bad class file: C:\Users\ram\.m2\repository\org\eclipse\platform\org.eclipse.equinox.common\3.15.0\org.eclipse.equinox.common-3.15.0.jar(org/eclipse/core/runtime/IPath.class)
class file has wrong version 55.0, should be 52.0
</p>
I am also attaching Dependency Hierarchy screenshots.
I just ran into a very similar issue. Managed to get it working again by downgrading from
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core</artifactId>
<version>3.27.0</version>
</dependency>
(which worked fine under java 8 up to a few weeks ago) to:
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core</artifactId>
<version>3.10.0</version>
</dependency>
which seems to still work fine with java 8, at least for the AST functionality I'm using in my project.
Based on the answer of #KC_911723 and #grubi you can use this configuration:
<dependencies>
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core</artifactId>
<version>3.23.0</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<!-- declare the exclusion here -->
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.core.runtime</artifactId>
</exclusion>
<exclusion>
<!-- declare the exclusion here -->
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.common</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.core.runtime</artifactId>
<version>3.13.0</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<!-- declare the exclusion here -->
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.common</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.common</artifactId>
<version>3.14.100</version>
<scope>compile</scope>
</dependency>
</dependencies>
or use this gradle configuration:
dependencies {
implementation ('org.eclipse.jdt:org.eclipse.jdt.core:3.23.0'){
exclude group: 'org.eclipse.platform', module: 'org.eclipse.core.runtime'
exclude group: 'org.eclipse.platform', module: 'org.eclipse.equinox.common'
}
implementation ('org.eclipse.platform:org.eclipse.core.runtime:3.13.0'){
exclude group: 'org.eclipse.platform', module: 'org.eclipse.equinox.common'
}
implementation 'org.eclipse.platform:org.eclipse.equinox.common:3.14.100'
}

ClassNotFound Exception when using jenkins and maven

I need your help. I'm just getting used to Java and have finished my first milestone in my private project. Now I wanted to use this milestone as an opportunity to deal with Jenkins and CI.
However, I run into problems when running the program via Maven in Jenkins. Maven always throws me a ClassNotFound exception when processing the Jenkins pipeline. But when I start the program locally in IntelliJ it runs without problems.
As far as I can see he can't find a POJO which I use for parsing XML using JAXB.
Why doesn't it find a class when I build using Jenkins but finds everything when I work locally, the POM is the same.
This is my POM:
<groupId>groupId</groupId>
<artifactId>rss_backend</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.11</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2.11</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.2.11</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>dev.morphia.morphia</groupId>
<artifactId>core</artifactId>
<version>1.5.8</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<mainClass>projects.rss_backend.MainApp</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
and this is the error i get when using jenkins/maven:
The following command runs and outputs the execution of your Java
application (which Jenkins built using Maven) to the Jenkins UI.
+ java -jar target/rss_backend-1.0-SNAPSHOT.jar
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
at projects.rss_backend.MainApp.main(MainApp.java:20)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 1 more```
Do you have a clue what I'm doing wrong or how I can fix the problem?
Normal jars do not contain dependencies.
You need to build an executable jar as described here: How can I create an executable JAR with dependencies using Maven?
Probably you did not start the jar from IntelliJ with java -jar but with some IntelliJ mechanism that did the magic (i.e. the classpath) for you.
I would suggest to upgrade your jaxb deps: The following are working for me in JDK11+:
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.4.0-b180830.0438</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.4.0-b180830.0359</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.4.0-b180830.0438</version>
</dependency>
As far as I can see, you are using Java 11, which means modules exist.
Did you declare your own module (create a module-info.java in your source folder)?
Most cases above Java 8 where I have seen a ClassNotFoundException, there was a module dependency missing. And that means that you cannot interact with whatever you are trying to do.
I am not familiar with Jenkins, however I assume that either
- your project requires something from Jenkins
or
- Jenkins tries to interact with something from your project via Reflection (e.g. building an object from a database).
In the first case, in your module-info.java, you would write
requires (transitive) jenkins-module-you-want-to-add ;
in the second case you would write
opens your-data-package to jenkins-module-that-needs-access ;
That is in my opinion the most likely source of the ClassNotFoundException you are receiving.
Anyhow, there is also the chance that maven is the source of your problem.

GAE - Class not found: Caused by: java.lang.ClassNotFoundExceptionAppIdentityCredential$AppEngineCredentialWrapper

I'm trying to launch a simple Java (Maven) Spring Boot application on GAE that communicates with an PostrgreSql server (also on the Cloud Platform) however I keep running into missing dependencies.
I had these dependencies in my pom:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter</artifactId>
<version>1.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-sql-postgresql</artifactId>
<version>1.1.3.RELEASE</version>
</dependency>
But whenever I deployed the app to GAE and the FlyWay the following was thrown:
java.lang.ClassNotFoundException: com.google.appengine.api.ThreadManager
I mainly followed the Baeldung tutorial here: https://www.baeldung.com/spring-boot-google-app-engine.
Then I found this answer: AppEngine ClassNotFoundException: com.google.appengine.api.datastore.DatastoreServiceFactory
Which led me to adding the appengine dependency:
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
<version>1.9.77</version>
</dependency>
Which then throws:
ClassNotFoundException: com.google.api.client.googleapis.extensions.appengine.auth.oauth2.AppIdentityCredential$AppEngineCredentialWrapper
Which then led me to adding the client dependency.. and so on.. and so on..
My complete set of dependencies is now:
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud</artifactId>
<version>0.47.0-alpha</version>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
<version>1.9.77</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter</artifactId>
<version>1.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-sql-postgresql</artifactId>
<version>1.1.3.RELEASE</version>
</dependency>
And that.. leads back to the exception above:
ClassNotFoundException: com.google.api.client.googleapis.extensions.appengine.auth.oauth2.AppIdentityCredential$AppEngineCredentialWrapper
So it is probably a dependency problem but I cannot for the life of my find any documentation about which dependencies you need to add to get a simple Spring Boot application running to a PostgreSQL server.
I'm about to throw in the towel...
It might be a lack of sleep though
You are missing the App Engine plugin in your pom.xml :
<build>
<plugins>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>1.3.2</version>
</plugin>
</plugins>
</build>
And for the exception you get, I do not know exactly where are you using this but you can add the dependency :
<dependency>
<groupId>com.google.auth</groupId>
<artifactId>google-auth-library-oauth2-http</artifactId>
<version>0.18.0</version>
</dependency>

Categories

Resources