JDK com.sun.tools Maven 安装后未找到
JDK com.sun.tools not found after Maven install
我的问题(MAVEN)只存在于Windows(不是Linux)而不是IDE(Eclipse)
Class:
...
System.out.println("Location of Tools --> " + VirtualMachine.class.getProtectionDomain().getCodeSource().getLocation());
...
异常:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/attach/VirtualMachine
at my.package.bootstrap(Controller.java:37)
at my.package.main(Main.java:35)
Caused by: java.lang.ClassNotFoundException: com.sun.tools.attach.VirtualMachine
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 2 more
我的环境:
Windows: Windows 10 (Here are the Problems!!!)
Linux: Xubuntu 16.04 (Works fine)
Java: 8 oracle (not openjdk!)
Maven (**using the maven-assembly-plugin for installing**)
我的项目架构:
My Project which using the com.sun.tools is a library: lib.jar
which gets used by Main Project: Main.jar.
I'm using maven to compile all of that into Main.jar
什么有效:
Linux Eclipse IDE: found
Linux - Shell: java -jar myjar.jar: found
Windows Eclipse IDE: found
--> Windows - Bash: /java_jdk_path/java -jar myjar.jar: _NOT_FOUND_
我的 not-working-solutions 让它在 main.jar:
中找到 windows 上的库
set %JAVA_HOME% ... to jdk
set %JRE_HOME% ... to jre
我发现了很多解决方法,例如 maven 配置文件等,我测试了所有这些方法,但没有任何效果。一度
当我通过 Maven 插件(mvn 安装...)将 com.sun.tools 复制到 JAR 中时,我成功了。然后就成功了。
但我需要它动态地找到 com.sun.tools - 取决于操作系统 linux 和 windows.
对我的下一步有什么建议吗?我不知道我能做什么它有效。
在使用 java -jar Main.jar
执行后,在 windows 上使用此 tools.jar 时,我总是会遇到此异常
目标:我想在我想要的任何文件夹上启动 Main.jar (java -jar Main.jar)。
更新:
我添加了一个示例项目,但由于此错误而对我来说完全失败。
只需创建一个新的 Maven 项目并将其添加到 Main.java
和 POM。安装它: mvn install 但它失败了。
使用 eclipse jar 构建器,它可以工作!??? WTF 为什么?
代码:
...
System.out.println("Location of Tools --> " + VirtualMachine.class.getProtectionDomain().getCodeSource().getLocation());
...
POM:
<properties>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.8</version>
<scope>system</scope>
<systemPath>${env.JAVA_HOME}/lib/tools.jar</systemPath>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<outputDirectory>C:\Output\</outputDirectory>
<archive>
<manifest>
<mainClass>com.test.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
我知道它不是当前问题的解决方案,但我正在使用一种解决方法,我可以将它推荐给任何其他人。我现在正在使用 https://github.com/oshi/oshi,因为它具有我需要并希望通过 com.sun.tools.
获得的所有功能
但不管怎样,如果有人对此 maven 安装(也许是 maven {java.home} 错误?)问题有可行的解决方案,那将是一件好事。
我的问题(MAVEN)只存在于Windows(不是Linux)而不是IDE(Eclipse)
Class:
...
System.out.println("Location of Tools --> " + VirtualMachine.class.getProtectionDomain().getCodeSource().getLocation());
...
异常:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/attach/VirtualMachine
at my.package.bootstrap(Controller.java:37)
at my.package.main(Main.java:35)
Caused by: java.lang.ClassNotFoundException: com.sun.tools.attach.VirtualMachine
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 2 more
我的环境:
Windows: Windows 10 (Here are the Problems!!!)
Linux: Xubuntu 16.04 (Works fine)
Java: 8 oracle (not openjdk!)
Maven (**using the maven-assembly-plugin for installing**)
我的项目架构:
My Project which using the com.sun.tools is a library: lib.jar
which gets used by Main Project: Main.jar.
I'm using maven to compile all of that into Main.jar
什么有效:
Linux Eclipse IDE: found
Linux - Shell: java -jar myjar.jar: found
Windows Eclipse IDE: found
--> Windows - Bash: /java_jdk_path/java -jar myjar.jar: _NOT_FOUND_
我的 not-working-solutions 让它在 main.jar:
中找到 windows 上的库set %JAVA_HOME% ... to jdk
set %JRE_HOME% ... to jre
我发现了很多解决方法,例如 maven 配置文件等,我测试了所有这些方法,但没有任何效果。一度 当我通过 Maven 插件(mvn 安装...)将 com.sun.tools 复制到 JAR 中时,我成功了。然后就成功了。
但我需要它动态地找到 com.sun.tools - 取决于操作系统 linux 和 windows.
对我的下一步有什么建议吗?我不知道我能做什么它有效。 在使用 java -jar Main.jar
执行后,在 windows 上使用此 tools.jar 时,我总是会遇到此异常目标:我想在我想要的任何文件夹上启动 Main.jar (java -jar Main.jar)。
更新: 我添加了一个示例项目,但由于此错误而对我来说完全失败。
只需创建一个新的 Maven 项目并将其添加到 Main.java 和 POM。安装它: mvn install 但它失败了。 使用 eclipse jar 构建器,它可以工作!??? WTF 为什么?
代码:
...
System.out.println("Location of Tools --> " + VirtualMachine.class.getProtectionDomain().getCodeSource().getLocation());
...
POM:
<properties>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.8</version>
<scope>system</scope>
<systemPath>${env.JAVA_HOME}/lib/tools.jar</systemPath>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<outputDirectory>C:\Output\</outputDirectory>
<archive>
<manifest>
<mainClass>com.test.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
我知道它不是当前问题的解决方案,但我正在使用一种解决方法,我可以将它推荐给任何其他人。我现在正在使用 https://github.com/oshi/oshi,因为它具有我需要并希望通过 com.sun.tools.
获得的所有功能但不管怎样,如果有人对此 maven 安装(也许是 maven {java.home} 错误?)问题有可行的解决方案,那将是一件好事。