英文:
java.lang.ClassNotFoundException: io.quarkus.runtime.Quarkus
问题
我正试图运行 Quarkus 应用程序的 runner jar,它将在端口9411上通过http进行监听。
在编程中使用 UrlClassLoader,当我尝试加载该jar时会抛出以下异常
(使用java -jar也是同样的情况)
-
java.lang.ClassNotFoundException: io.quarkus.runtime.Quarkus
-
java.lang.reflect.InvocationTargetException
以下是代码片段,
URLClassLoader loader = new URLClassLoader(
new URL[]{ new File(<runner jar 的位置>).toURI().toURL()});
Thread.currentThread().setContextClassLoader(loader);
Class<?> mainClass = loader.loadClass("io.quarkus.runner.GeneratedMain");
Method mainMethod = mainClass.getMethod("main", String[].class);
mainMethod.invoke(null, (Object) new String[]{});
另一个观察结果是,当我将/lib文件夹放置在runner jar的位置时,它可以成功加载,这意味着它需要/lib文件夹。
如何使我的代码只能与runner jar一起工作呢?
英文:
I am trying to run runner jar of the quarkus application which would be listening over port 9411 on http.
Programmatically using UrlClassLoader, when I try to load the jar it throws
(also with java -jar)
1.java.lang.ClassNotFoundException: io.quarkus.runtime.Quarkus
2.java.lang.reflect.InvocationTargetException
here is the snippet of code ,
URLClassLoader loader = new URLClassLoader(
new URL[]{ new File(<location of runner jar>).toURI().toURL()});
Thread.currentThread().setContextClassLoader(loader);
Class<?> mainClass = loader.loadClass("io.quarkus.runner.GeneratedMain");
Method mainMethod = mainClass.getMethod("main", String[].class);
mainMethod.invoke(null, (Object) new String[]{});
another observation is when I place /lib folder at the runner jar location it loads successfully meaning it requires the lib folder altogether.
How can I make my code work only with runner jar?
答案1
得分: 7
生成包含运行应用程序所需所有库的可执行 JAR 文件,使用属性 quarkus.package.uber-jar=true
(您可以将其添加到 src/main/resources/application.properties
文件中,或者在运行构建时将其作为系统属性传递)。
英文:
To produce a fat jar that includes all the libraries necessary to run the app, use the property quarkus.package.uber-jar=true
(you can add that into src/main/resources/application.properties
or pass it as a system property when running the build).
答案2
得分: 2
使用 mvn clean package
命令时,我遇到了以下启动错误:
无法识别配置键"quarkus.package.uber-jar"。
我已经找到了如下属性:
quarkus.package.type=uber-jar
作为一个属性。
我更喜欢在 POM 属性中进行如下设置:
<quarkus.package.type>uber-jar</quarkus.package.type>
链接:https://github.com/fluentcodes/sandbox/tree/java-quarkus-empty
英文:
With mvn clean package I got the following error starting:
Unrecognized configuration key "quarkus.package.uber-jar" was provided
I've found
quarkus.package.type=uber-jar
as a property.
What I prefer is setting
<quarkus.package.type>uber-jar</quarkus.package.type>
in the pom properties.
https://github.com/fluentcodes/sandbox/tree/java-quarkus-empty
答案3
得分: 0
Sure, here are the translations:
- 如果你想使用Gradle构建一个_über-jar
./gradlew build -Dquarkus.package.type=uber-jar
- 如果有人在使用
serverless framework
,请确保你的构建产物是function.zip
,而不是一个jar,在Quarkus JDK模式下。
package:
artifact: build/function.zip
- 如果有人在使用ALB来调用Lambda函数,那么你需要在你的gradle中将
'io.quarkus:quarkus-amazon-lambda'
替换为'io.quarkus:quarkus-amazon-lambda-rest'
。在这种情况下,你不需要提供一个自定义的处理程序实现。
英文:
- If you want to build an _über-jar with Gradle
./gradlew build -Dquarkus.package.type=uber-jar
- If anyone is using
serverless framework
, make sure your artifact isfunction.zip
not a jar in Quarkus JDK mode.
package:
artifact: build/function.zip
- If anyone is using ALB to invoke the lambda then you have to replace the
'io.quarkus:quarkus-amazon-lambda'
by'io.quarkus:quarkus-amazon-lambda-rest'
in your grade. In that case, you don't need to provide a custom handler implementation.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论