java.lang.ClassNotFoundException: io.quarkus.runtime.Quarkus

huangapple go评论79阅读模式
英文:

java.lang.ClassNotFoundException: io.quarkus.runtime.Quarkus

问题

我正试图运行 Quarkus 应用程序的 runner jar,它将在端口9411上通过http进行监听。

在编程中使用 UrlClassLoader,当我尝试加载该jar时会抛出以下异常
(使用java -jar也是同样的情况)

  1. java.lang.ClassNotFoundException: io.quarkus.runtime.Quarkus

  2. 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(&lt;location of runner jar&gt;).toURI().toURL()});
        Thread.currentThread().setContextClassLoader(loader);
        Class&lt;?&gt; mainClass = loader.loadClass(&quot;io.quarkus.runner.GeneratedMain&quot;); 
        Method mainMethod = mainClass.getMethod(&quot;main&quot;, 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 &quot;quarkus.package.uber-jar&quot; was provided

I've found

 quarkus.package.type=uber-jar 

as a property.

What I prefer is setting

 &lt;quarkus.package.type&gt;uber-jar&lt;/quarkus.package.type&gt;

in the pom properties.

https://github.com/fluentcodes/sandbox/tree/java-quarkus-empty

答案3

得分: 0

Sure, here are the translations:

  1. 如果你想使用Gradle构建一个_über-jar
./gradlew build -Dquarkus.package.type=uber-jar
  1. 如果有人在使用serverless framework,请确保你的构建产物是function.zip,而不是一个jar,在Quarkus JDK模式下。
package:
  artifact: build/function.zip
  1. 如果有人在使用ALB来调用Lambda函数,那么你需要在你的gradle中将&#39;io.quarkus:quarkus-amazon-lambda&#39;替换为&#39;io.quarkus:quarkus-amazon-lambda-rest&#39;。在这种情况下,你不需要提供一个自定义的处理程序实现。
英文:
  1. If you want to build an _über-jar with Gradle
./gradlew build -Dquarkus.package.type=uber-jar
  1. If anyone is using serverless framework, make sure your artifact is function.zip not a jar in Quarkus JDK mode.
package:
  artifact: build/function.zip
  1. If anyone is using ALB to invoke the lambda then you have to replace the &#39;io.quarkus:quarkus-amazon-lambda&#39; by &#39;io.quarkus:quarkus-amazon-lambda-rest&#39; in your grade. In that case, you don't need to provide a custom handler implementation.

huangapple
  • 本文由 发表于 2020年9月16日 15:29:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/63915143.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定