私の問題をインストールした後、JDKが見つからないcom.sun.tools:MavenのがちょうどIDE(Eclipseの)内部</p> <p>クラス(Linuxではなく)Windows上存在しない(<em>MAVEN</em>付き)
...
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_
を、それがmain.jarのウィンドウ上のlibを見つけるようにするマイない -working-ソリューション:
set %JAVA_HOME% ... to jdk
set %JRE_HOME% ... to jre
私はMavenのプロファイルのような多くの回避策を見つけました。私はすべてをテストしましたが、何も動作しませんed。 1回 mavenプラグイン(mvn install ...)を使用してcom.sun.toolsをJARにコピーしたときに、うまくいきました。その後、それは働いた。
しかし、オペレーティングシステムのLinuxとWindowsに応じて、com.sun.toolsを動的に見つける必要があります。
私の次のステップの提案はありますか?私はそれがうまくいくかどうかわからない。 Windowsでこのtools.jarを使用すると、この例外が発生します。java -jar Main.jar
目的:Main.jar(java -jar Main.jar)を私が望むフォルダ。
UPDATE: 私はまさにこのエラーで私のために失敗したサンプルプロジェクトを、追加しました。
新しいMavenプロジェクトを作成し、これをMain.java とPOMに追加するだけです。それをインストールする:mvn installそれは失敗する。 エクリプス・ジャー・ビルダーを使用してください!なぜか?
コード:
...
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>
com.sun。*クラスのjaveは、JavaパブリックAPIの一部ではありませんでした。それらは使用してはならず、自由に変更または削除することができます(そして、私は異なるベンダーのJava実装にも存在しません)。 – hardillb
IDEはインストールディレクトリ内に埋め込まれた別のJavaランタイムを使用している可能性があります。その場所で実行可能なjavaを使用してコードを実行してみてください。 –
私は自分の目標を追加しました。 – thunder