简体   繁体   English

tools.jar 未打包到 maven package 中。 获取 java.lang.NoClassDefFoundError: com/sun/tools/javadoc/Main

[英]tools.jar not packaged into the maven package. Getting java.lang.NoClassDefFoundError: com/sun/tools/javadoc/Main

I have created a maven project which needs tools.jar to be included.我创建了一个 maven 项目,该项目需要 tools.jar 被包括在内。 I have added the jar into the lib folder and included the following in the pom.xml.我已将 jar 添加到 lib 文件夹中,并在 pom.xml 中包含以下内容。

<dependency>
            <groupId>com.sun</groupId>
            <artifactId>tools</artifactId>
            <scope>system</scope>
            <version>1.8.0</version>
            <systemPath>${project.basedir}\src\lib\tools.jar</systemPath>
</dependency>

When have also added the following plugin to create executable jar for the project.当还添加了以下插件来为项目创建可执行 jar。

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>umlparser.Main</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>

I have built the jar using "mvn clean package assembly:single" This has created an executable jar file with name myproject-jar-with-dependencies.我已经使用“mvn clean package assembly:single”构建了 jar 这已经创建了一个名为 myproject-jar-with-dependencies 的可执行 jar 文件

But when I am trying to run the jar file with java -jar it is unable to get the tools.jar.但是,当我尝试使用 java -jar 运行 jar 文件时,它无法获取工具。jar。 I am getting the following error我收到以下错误

Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javadoc/Main
        at org.umlgraph.doclet.UmlGraph.main(UmlGraph.java:70)
        at umlparser.Main.main(Main.java:19)
Caused by: java.lang.ClassNotFoundException: com.sun.tools.javadoc.Main
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 2 more

But when I am exporting it as runnable jar from eclipse it is working as expected.但是,当我从 eclipse 将其导出为可运行的 jar 时,它按预期工作。 What is the issue with the maven package? maven package 有什么问题? Am I missing something here?我在这里错过了什么吗?

EDIT编辑

I have tried to import the tools.jar dependency from the java_home instead of project path.我试图从 java_home 而不是项目路径导入 tools.jar 依赖项。

<dependency>
            <groupId>com.sun</groupId>
            <artifactId>tools</artifactId>
            <version>1.8.0_241</version>
            <scope>system</scope>
            <systemPath>${java.home}/../lib/tools.jar</systemPath>
        </dependency>

Still I am getting the same issue.我仍然遇到同样的问题。

Note: The tools.jar is not used in my program.注意:我的程序中没有使用 tools.jar。 It is being used by one of the jars that I have included - "UMLGraph.jar".我包含的 jars 之一正在使用它 - “UMLGraph.jar”。

The com.sun:tools dependency which you have added has a system scope.您添加的com.sun:tools依赖项具有system scope。 Dependencies with provided and system scopes will not be includes in such packaged artifacts. provided的和system范围的依赖项将不包含在此类打包的工件中。

Specifically in this case, you should also actually not be doing so, because this jar comes as part of your JDK.特别是在这种情况下,您实际上也不应该这样做,因为这个 jar 是您的 JDK 的一部分。 The users of your jar will have a JDK/JRE to run the code and if you include tools jar you will most-likely be causing a conflict with their JDK/JRE and you really don't want to be doing that.您的 jar 的用户将拥有一个 JDK/JRE 来运行代码,如果您包含 jar tools ,您很可能会与他们的 JDK/JRE 发生冲突,而您真的不想这样做。

This being said, you could probably try using dependencySet with a scope of system , but I would really not advise this (even if it does the trick).话虽这么说,您可能可以尝试将dependencySetsystemscope一起使用,但我真的不建议这样做(即使它成功了)。

I'm assuming that on the system where you're running this jar, you simply don't have the JDK on your PATH and you have just the JRE instead.我假设在您运行此 jar 的系统上,您的PATH中根本没有 JDK,而只有 JRE。 If you fix this, you should not have to do any of this unconventional hacking around.如果你解决了这个问题,你不应该做任何这种非常规的黑客攻击。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.NoClassDefFoundError:com / sun / tools / javac / Main - java.lang.NoClassDefFoundError: com/sun/tools/javac/Main java.lang.NoClassDefFoundError:com / sun / istack / tools / DefaultAuthenticator $ Receiver - java.lang.NoClassDefFoundError: com/sun/istack/tools/DefaultAuthenticator$Receiver java.lang.NoClassDefFoundError:com / sun / tools / javac / Main SOAP UI - java.lang.NoClassDefFoundError: com/sun/tools/javac/Main SOAP UI 取决于Eclipse中tools.jar(Sun JDK)的com.sun.javadoc - Depending on com.sun.javadoc from tools.jar (Sun JDK) in Eclipse java.lang.NoClassDefFoundError:com / sun / tools / corba / se / idl / InvalidArgument - java.lang.NoClassDefFoundError: com/sun/tools/corba/se/idl/InvalidArgument java.lang.NoClassDefFoundError:com / google / appengine / tools / cloudstorage / GcsFilename - java.lang.NoClassDefFoundError: com/google/appengine/tools/cloudstorage/GcsFilename 获取错误“java.lang.NoClassDefFoundError:com.android.tools.fd.runtime.AppInfo” - Getting Error “java.lang.NoClassDefFoundError: com.android.tools.fd.runtime.AppInfo” Java + Maven1.x:如何添加sun的tools.jar? - Java + Maven1.x : how to add sun's tools.jar? Android javadoc,com.sun.tools.javac.util.FatalError:致命错误:无法在类路径或引导类路径中找到包java.lang - Android javadoc, com.sun.tools.javac.util.FatalError: Fatal Error: Unable to find package java.lang in classpath or bootclasspath java.lang.NoClassDefFoundError: org/openxmlformats/schemas/spreadsheetml/x2006/main/CTSheet 在 com.macrorecorder.gui.tools.ExcelFile.main - java.lang.NoClassDefFoundError: org/openxmlformats/schemas/spreadsheetml/x2006/main/CTSheet at com.macrorecorder.gui.tools.ExcelFile.main
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM