question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

hibernate with jbang fails with class loader issue

See original GitHub issue

Describe the bug use this code:

//usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS io.quarkus:quarkus-picocli:1.8.0.CR1
//DEPS io.quarkus:quarkus-hibernate-orm-panache:1.8.0.CR1
//DEPS io.quarkus:quarkus-jdbc-postgresql:1.8.0.CR1
//JAVA_OPTIONS -Djava.util.logging.manager=org.jboss.logmanager.LogManager
//Q:CONFIG quarkus.banner.enabled=false
//Q:CONFIG quarkus.log.level=WARN
//Q:CONFIG quarkus.datasource.db-kind = postgresql
//Q:CONFIG quarkus.datasource.username = sarah
//Q:CONFIG quarkus.datasource.password = connor
//Q:CONFIG quarkus.datasource.jdbc.url = jdbc:tc:postgresql:9.6.8:///databasename
//Q:CONFIG quarkus.hibernate-orm.database.generation = drop-and-create

import io.quarkus.hibernate.orm.panache.PanacheEntity;
import picocli.CommandLine;

import javax.enterprise.context.Dependent;
import javax.inject.Inject;
import javax.persistence.Entity;

import io.quarkus.runtime.annotations.QuarkusMain;
import io.quarkus.runtime.QuarkusApplication;

import java.time.LocalDate;
import java.util.List;

@QuarkusMain
@CommandLine.Command 
public class quarkusclidb implements Runnable, QuarkusApplication {

    @CommandLine.Option(names = {"-n", "--name"}, description = "Who will we greet?", defaultValue = "World")
    String name;

    @Inject
    CommandLine.IFactory factory; 

    private final GreetingService greetingService;

    public quarkusclidb(GreetingService greetingService) {
        this.greetingService = greetingService;
    }

    @Override
    public void run() {
        greetingService.sayHello(name);
    }

    @Override
    public int run(String... args) throws Exception {
        return new CommandLine(this, factory).execute(args);
    }

    public static void main(String... args) {
        io.quarkus.runtime.Quarkus.run(quarkusclidb.class, args);
    }

    @Entity
    static public class Person extends PanacheEntity {
        public String name;
        public LocalDate birth;
        public String status;

        public static Person findByName(String name){
            return find("name", name).firstResult();
        }

        public static List<Person> findAlive(){
            return list("status", "alive");
        }

        public static void deleteStefs(){
            delete("name", "Stef");
        }
    }
}

@Dependent
class GreetingService {
    void sayHello(String name) {
        System.out.println("Hello " + name + "!");
    }
}

build/run it with: jbang quarkusclidb.java

and you get:

[jbang] Post build with io.quarkus.launcher.JBangIntegration
Sep 05, 2020 12:42:05 AM org.jboss.threads.Version <clinit>
INFO: JBoss Threads version 3.1.1.Final
Sep 05, 2020 12:42:05 AM io.quarkus.agroal.deployment.AgroalProcessor build
WARN: The Agroal dependency is present but no JDBC datasources have been defined.
dev.jbang.ExitException: Issue running postBuild()
	at dev.jbang.IntegrationManager.runIntegration(IntegrationManager.java:116)
	at dev.jbang.cli.Run.build(Run.java:217)
	at dev.jbang.cli.Run.doCall(Run.java:97)
	at dev.jbang.cli.BaseCommand.call(BaseCommand.java:59)
	at dev.jbang.cli.BaseCommand.call(BaseCommand.java:13)
	at picocli.CommandLine.executeUserObject(CommandLine.java:1933)
	at picocli.CommandLine.access$1100(CommandLine.java:145)
	at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2332)
	at picocli.CommandLine$RunLast.handle(CommandLine.java:2326)
	at picocli.CommandLine$RunLast.handle(CommandLine.java:2291)
	at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2159)
	at picocli.CommandLine.execute(CommandLine.java:2058)
	at dev.jbang.Main.main(Main.java:14)
Caused by: java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at dev.jbang.IntegrationManager.runIntegration(IntegrationManager.java:89)
	... 12 more
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
	at io.quarkus.launcher.JBangIntegration.postBuild(JBangIntegration.java:85)
	... 17 more
Caused by: java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at io.quarkus.launcher.JBangIntegration.postBuild(JBangIntegration.java:77)
	... 17 more
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
	[error]: Build step io.quarkus.hibernate.orm.deployment.HibernateOrmProcessor#parsePersistenceXmlDescriptors threw an exception: java.lang.NoClassDefFoundError: org/xml/sax/SAXException
	at io.quarkus.hibernate.orm.deployment.HibernateOrmProcessor.parsePersistenceXmlDescriptors(HibernateOrmProcessor.java:225)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:936)
	at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
	at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
	at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:2046)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1578)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1452)
	at java.base/java.lang.Thread.run(Thread.java:834)
	at org.jboss.threads.JBossThread.run(JBossThread.java:479)
Caused by: java.lang.ClassNotFoundException: org.xml.sax.SAXException
	at io.quarkus.launcher.RuntimeLaunchClassLoader.findClass(RuntimeLaunchClassLoader.java:25)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
	at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:406)
	at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:363)
	... 13 more

	at io.quarkus.bootstrap.JBangBuilderImpl.postBuild(JBangBuilderImpl.java:81)
	... 22 more
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
	[error]: Build step io.quarkus.hibernate.orm.deployment.HibernateOrmProcessor#parsePersistenceXmlDescriptors threw an exception: java.lang.NoClassDefFoundError: org/xml/sax/SAXException
	at io.quarkus.hibernate.orm.deployment.HibernateOrmProcessor.parsePersistenceXmlDescriptors(HibernateOrmProcessor.java:225)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:936)
	at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
	at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
	at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:2046)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1578)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1452)
	at java.base/java.lang.Thread.run(Thread.java:834)
	at org.jboss.threads.JBossThread.run(JBossThread.java:479)
Caused by: java.lang.ClassNotFoundException: org.xml.sax.SAXException
	at io.quarkus.launcher.RuntimeLaunchClassLoader.findClass(RuntimeLaunchClassLoader.java:25)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
	at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:406)
	at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:363)
	... 13 more

	at io.quarkus.bootstrap.app.CuratedApplication.runInCl(CuratedApplication.java:132)
	at io.quarkus.bootstrap.app.CuratedApplication.runInAugmentClassLoader(CuratedApplication.java:82)
	at io.quarkus.bootstrap.JBangBuilderImpl.postBuild(JBangBuilderImpl.java:78)
	... 22 more
Caused by: java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
	[error]: Build step io.quarkus.hibernate.orm.deployment.HibernateOrmProcessor#parsePersistenceXmlDescriptors threw an exception: java.lang.NoClassDefFoundError: org/xml/sax/SAXException
	at io.quarkus.hibernate.orm.deployment.HibernateOrmProcessor.parsePersistenceXmlDescriptors(HibernateOrmProcessor.java:225)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:936)
	at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
	at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
	at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:2046)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1578)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1452)
	at java.base/java.lang.Thread.run(Thread.java:834)
	at org.jboss.threads.JBossThread.run(JBossThread.java:479)
Caused by: java.lang.ClassNotFoundException: org.xml.sax.SAXException
	at io.quarkus.launcher.RuntimeLaunchClassLoader.findClass(RuntimeLaunchClassLoader.java:25)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
	at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:406)
	at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:363)
	... 13 more

	at io.quarkus.deployment.jbang.JBangAugmentorImpl.accept(JBangAugmentorImpl.java:119)
	at io.quarkus.deployment.jbang.JBangAugmentorImpl.accept(JBangAugmentorImpl.java:36)
	at io.quarkus.bootstrap.app.CuratedApplication.runInCl(CuratedApplication.java:129)
	... 24 more
Caused by: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
	[error]: Build step io.quarkus.hibernate.orm.deployment.HibernateOrmProcessor#parsePersistenceXmlDescriptors threw an exception: java.lang.NoClassDefFoundError: org/xml/sax/SAXException
	at io.quarkus.hibernate.orm.deployment.HibernateOrmProcessor.parsePersistenceXmlDescriptors(HibernateOrmProcessor.java:225)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:936)
	at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
	at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
	at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:2046)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1578)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1452)
	at java.base/java.lang.Thread.run(Thread.java:834)
	at org.jboss.threads.JBossThread.run(JBossThread.java:479)
Caused by: java.lang.ClassNotFoundException: org.xml.sax.SAXException
	at io.quarkus.launcher.RuntimeLaunchClassLoader.findClass(RuntimeLaunchClassLoader.java:25)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
	at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:406)
	at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:363)
	... 13 more

	at io.quarkus.builder.Execution.run(Execution.java:116)
	at io.quarkus.builder.BuildExecutionBuilder.execute(BuildExecutionBuilder.java:79)
	at io.quarkus.deployment.QuarkusAugmentor.run(QuarkusAugmentor.java:149)
	at io.quarkus.deployment.jbang.JBangAugmentorImpl.accept(JBangAugmentorImpl.java:97)
	... 26 more
Caused by: java.lang.NoClassDefFoundError: org/xml/sax/SAXException
	at io.quarkus.hibernate.orm.deployment.HibernateOrmProcessor.parsePersistenceXmlDescriptors(HibernateOrmProcessor.java:225)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:936)
	at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
	at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
	at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:2046)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1578)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1452)
	at java.base/java.lang.Thread.run(Thread.java:834)
	at org.jboss.threads.JBossThread.run(JBossThread.java:479)
Caused by: java.lang.ClassNotFoundException: org.xml.sax.SAXException
	at io.quarkus.launcher.RuntimeLaunchClassLoader.findClass(RuntimeLaunchClassLoader.java:25)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
	at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:406)
	at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:363)
	... 13 more

Probably similar issue as in #11542 where we found places TCCL was not put as a fallback for class.forname.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
Sannecommented, Sep 7, 2020

hum, sorry yes it seemed to work but I forgot to use --verbose. It actually still fails.

0reactions
maxandersencommented, Sep 8, 2020

with #11957 this updated (as the original had bugs/was incomplete) works:

//usr/bin/env jbang "$0" "$@" ; exit $?
/**
 * Run this with `jbang -Dquarkus.container-image.build=true build quarkus.java`
 * and it builds a docker image.
 */
//DEPS io.quarkus:quarkus-picocli:${q.v:1.8.0.CR1}
//DEPS io.quarkus:quarkus-hibernate-orm-panache:${q.v:1.8.0.CR1}
//DEPS io.quarkus:quarkus-jdbc-postgresql:${q.v:1.8.0.CR1}
//DEPS org.testcontainers:postgresql:1.14.3
//DEPS org.postgresql:postgresql:42.1.4
//JAVA_OPTIONS -Djava.util.logging.manager=org.jboss.logmanager.LogManager
//Q:CONFIG quarkus.banner.enabled=false
//Q:CONFIG quarkus.log.level=WARN
//Q:CONFIG quarkus.datasource.db-kind=postgresql
//Q:CONFIG quarkus.datasource.username=sarah
//Q:CONFIG quarkus.datasource.password=connor
//Q:CONFIG quarkus.datasource.jdbc.url=jdbc:postgresql:databasename
//Q:CONFIG quarkus.hibernate-orm.database.generation=drop-and-create

import com.github.dockerjava.api.command.CreateContainerCmd;
import com.github.dockerjava.api.exception.NotFoundException;
import com.github.dockerjava.api.model.ExposedPort;
import com.github.dockerjava.api.model.PortBinding;
import com.github.dockerjava.api.model.Ports;
import io.quarkus.hibernate.orm.panache.PanacheEntity;
import org.testcontainers.containers.PostgreSQLContainer;
import picocli.CommandLine;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.Dependent;
import javax.enterprise.context.control.ActivateRequestContext;
import javax.inject.Inject;
import javax.persistence.Entity;
import javax.transaction.Transactional;

import io.quarkus.runtime.annotations.QuarkusMain;
import io.quarkus.runtime.QuarkusApplication;

import java.time.LocalDate;
import java.time.Month;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;

@QuarkusMain
@CommandLine.Command 
public class quarkusclidb implements Runnable, QuarkusApplication {

    @CommandLine.Option(names = {"-n", "--name"}, description = "Who will we greet?", defaultValue = "World")
    String name;

    @Inject
    CommandLine.IFactory factory; 

    private final GreetingService greetingService;

    public quarkusclidb(GreetingService greetingService) {
        this.greetingService = greetingService;
    }

    @Override
    @ActivateRequestContext
    @Transactional
    public void run() {
       greetingService.sayHello(name);
    }

    @Override
    public int run(String... args) throws Exception {
        return new CommandLine(this, factory).execute(args);
    }

    public static void main(String... args) {
        int hostPort = 5432;
        int containerExposedPort = 5432;

        Consumer<CreateContainerCmd> cmd = e -> e.withPortBindings(new PortBinding((Ports.Binding.bindPort(hostPort)),new ExposedPort(containerExposedPort)));

        var dbcontainer = new PostgreSQLContainer("postgres:11.1").withDatabaseName("databasename")
        .withUsername("sarah").withPassword("connor").withCreateContainerCmdModifier(cmd);

        dbcontainer.start();
        io.quarkus.runtime.Quarkus.run(quarkusclidb.class, args);
    }

    @Entity
    static public class Person extends PanacheEntity {
        public String name;
        public LocalDate birth;
        public String status;

        public static Person findByName(String name){
            return find("name", name).firstResult();
        }

        public static List<Person> findAlive(){
            return list("status", "alive");
        }

        public static void deleteStefs(){
            delete("name", "Stef");
        }
    }

    @Dependent
    static public class GreetingService {
        void sayHello(String name) {

            // creating a person
            Person person = new Person();
            person.name = "Stef";
            person.birth = LocalDate.of(1910, Month.FEBRUARY, 1);
            person.status = "alive";

            // persist it
            person.persist();

            List<Person> allPersons = Person.listAll();

            allPersons.forEach(System.out::println);

            long countAll = Person.count();

            System.out.println("Person count:" + countAll);

        }
    }
}


Read more comments on GitHub >

github_iconTop Results From Across the Web

JPA class loading issue with Hibernate - java - Stack Overflow
The issue was that the libraries that loads the libraries which scans for annotated @Entity classes is not in the lib folder for...
Read more >
Class Loading Reference - Quarkus
When running a production application using the legacy-jar package type everything is loaded in the system ClassLoader, so it is a completely flat...
Read more >
Home of Quarkus Cheat-Sheet - GitHub Pages
Quarkus is a Kubernetes Native Java stack tailored for GraalVM & OpenJDK HotSpot, crafted from the best of breed Java libraries and standards....
Read more >
quarkusio/quarkus 1.8.0.Final on GitHub - NewReleases.io
CR1; #11913 - hibernate with jbang fails with class loader issue; #11912 - Make native tests work with random port; #11911 - -Dquarkus.http.host=0.0.0.0 ......
Read more >
Unable to load class InfinispanDirectoryProvider - JBoss.org
I'm trying to create a project in wildfly 10 using infinispan as second cache for hibernate. When deploying my project I get the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found