我在尝试使用 vertx 时遇到了一些麻烦。我正在 Windows 上使用 IntelliJ 进行开发。
我只是想实例化一个 vertx 对象,如下所示:vertx vertx = Vertx.vertx()
。
在 Windows 上运行 int 时,我收到有关 netty 的警告:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by io.netty.util.internal.ReflectionUtil (file:/C:/Users/souki/.m2/repository/io/netty/netty-common/4.1.19.Final/netty-common-4.1.19.Final.jar) to constructor java.nio.DirectByteBuffer(long,int)
WARNING: Please consider reporting this to the maintainers of io.netty.util.internal.ReflectionUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
但是应用程序不会停止并且工作正常。但由于某些原因,我无法在 Windows 上测试我的程序,而必须在 Linux 虚拟机上运行它。
当按照 java -jar myjar.jar
在虚拟机上运行它时,我收到以下错误:
Exception in thread "main" java.lang.NoClassDefFoundError: io/vertx/core/Vertx
at Ecmg.main(Ecmg.java:16)
Caused by: java.lang.ClassNotFoundException: io.vertx.core.Vertx
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
当我删除 Vertx vertx = Vertx.vertx();
时,一切正常。
我的问题是,为什么我在 Linux 上遇到此错误?
如果您想知道,Linux 上的 java -version 输出是:
OpenJDK Runtime Environment (build 1.8.0_20-b26)
OpenJDK Server VM (build 25.20-b23, mixed mode)
这是我的 pom.xml :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>JavaEcmg</groupId>
<artifactId>JavaEcmg</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>3.5.1</version>
</dependency>
</dependencies>
</project>
关于我的 Intellij 配置:
提前致谢!
最佳答案
关于 JVM 警告:欢迎使用 Java 9 和 10 :-) (但是,是的,它工作得很好)
您可能会收到 ClassNotFoundException
,因为 Jar 仅由您的代码类组成。尝试构建一个 fat jar 子,如 https://github.com/vert-x3/vertx-examples/tree/master/fatjar-examples 所示
关于java - 无法实例化 vertx 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50005308/