ClassNotFoundException in quarkus jar when starting class in a new process #29531
Unanswered
adrian-salmeron
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey! I have probably a rather unique situation. I have a quarkus REST API and in one endpoint i need to start code with managed beans in a new process (a new thread is not sufficient due to hibernate context getting lost in the new thread and i need to do db operations in this process). So i saw here that you can start a class in a new process (so you dont have to extract it into a separate Java project to generate an executable .jar for it): https://dzone.com/articles/running-a-java-class-as-a-subprocess
My problem is, when i do this in my quarkus project, the calling of the new process throws a "ClassNotFoundException" - apparently the class does not exist (although it does exist in the same package in the compile jar). Is this some quarkus specific issue with how it compiles the project? Would the bean injection even work in the new process if the process was successfully started? I don't know how quarkus would work with this (i.e. although its started from the same code base, would the context be present in the new process?)
I have a quarkus REST API project with a situation where i need to execute a part of my code in a new process (not new thread, because the hibernate context gets lost in the new thread for database operations) when a call to an API endpoint is made, but i do not want to extract this code into a whole new project so i can generate a separate .jar file i can execute as a new process. Instead, i saw that you can start a class in your own project as a new process here: https://dzone.com/articles/running-a-java-class-as-a-subprocess
My calling code (the endpoint) looks like this:
Basically, the JobRunnerProcessCaller component in the createJob method starts the new process from a class that is in the same project and package (directly next to it):
The code (class JobRunnerProcessExecutor looks like this (with a main method, as required to be run/started in a new process):
Everything else executes fine, with no exception or error on the API endpoint process. However, if i look at the output console i can see the exception message after the process is started (or attempted, i suppose):
Error: Could not find or load main class com.example.platform.bot.JobRunnerProcessExecutor Caused by: java.lang.ClassNotFoundException: com.example.platform.bot.JobRunnerProcessExecutor
I am super confused and need some help, please!
Edit: I also printed the command arguments for the call:
C:\Program Files\Eclipse Adoptium\jdk-17.0.4.101-hotspot\bin\java
-cp
C:\Users\User1\Documents\projects\MyProject\backend\bot\target\myproject-dev.jar
com.example.platform.bot.JobRunnerProcessExecutor
2
Seems everything is correct to me. What is going on with Java being unable to load it from the quarkus jar?
I start the app with: .\mvnw quarkus:dev
Standalone compilation with: mvn clean install -DskipTests
Beta Was this translation helpful? Give feedback.
All reactions