我为Apache Storm
拓扑创建了一个包含所有依赖项的胖jar。我使用mvn clean dependency:copy-dependencies package
命令来创建这个jar。当我将此jar提交给Storm时,会出现以下错误:
Caused by: java.lang.ClassNotFoundException: com.sun.tools.corba.se.idl.InvalidArgument
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
我想知道如何解决此错误?哪个jar文件包含这个类?
编辑:添加pom.xml
<dependencies>
<dependency>
<groupId>com.ads.iot</groupId>
<artifactId>commons-for-iot</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.storm</groupId>
<artifactId>storm-kafka</artifactId>
<version>0.10.0-beta1</version>
</dependency>
<dependency>
<groupId>org.apache.storm</groupId>
<artifactId>storm-hbase</artifactId>
<version>0.10.0-beta1</version>
</dependency>
<dependency>
<groupId>org.apache.storm</groupId>
<artifactId>storm-core</artifactId>
<version>0.10.0-beta1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jdk.tools</groupId>
<artifactId>jdk.tools</artifactId>
<version>1.7.0_21</version>
<scope>system</scope>
<systemPath>${JAVA_HOME}/lib/tools.jar</systemPath>
</dependency>
</dependencies>
编辑2:pom.xml的插件部分
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<includeProjectDependencies>true</includeProjectDependencies>
<includePluginDependencies>false</includePluginDependencies>
<classpathScope>compile</classpathScope>
<mainClass>${main.class}</mainClass>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.ats.ift.KafkaStormTopologyBuilder</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
答案 0 :(得分:3)
您要部署到哪个版本的Java?浏览您的依赖项,我在JDK1.7的com/sun/tools/corba/se/idl/InvalidArgument.class
中找到tools.jar
。但是在JDK1.8中没有这样的库。事实上,1.8的一个变化是从com.sun
包中删除旧的非公共API。
我担心这里需要升级您的代码(到当前的公共API)。
答案 1 :(得分:1)
您需要在pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.9</version><!--$NO-MVN-MAN-VER$-->
<executions>
<execution>
<id>unpack</id>
<phase>prepare-package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>jdk.tools</groupId>
<artifactId>jdk.tools</artifactId>
<version>1.7.0_21</version>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
<includes>**</includes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
它将依赖jar复制并提取到target/classes
,这是文件夹maven-jar-plugin
期望它必须打包的所有类。这应该适用于mvn clean package
。
<强>更新强>
在您的情况下,需要先将tools.jar
安装到maven资源库中(https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html),因为maven-dependency-plugin
会在那里查找jar文件。