A few days ago I setup my first Maven 2 enabled struts 2.0 WTP project. After an hour of muddling through the Eclipse IDE setup with WTP plus Maven, I soon ran into another trouble when I built the project in Eclipse. Maven told me that it missed the com.sun tools artifact that it couldn’t build the project.
Missing dependency tools.jar
8/13/07 5:58:51 PM CST: Missing:
1) com.sun:tools:jar:1.5.0
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=com.sun -DartifactId=tools \
-Dversion=1.5.0 -Dpackaging=jar -Dfile=/path/to/file
Path to dependency:
1) tutorial:tutorial4:war:1.0-SNAPSHOT
2) org.apache.struts:struts2-core:jar:2.0.5
3) com.sun:tools:jar:1.5.0
1 required artifact is missing.
for artifact:
tutorial:tutorial4:war:1.0-SNAPSHOT
from the specified remote repositories:
central (http://repo1.maven.org/maven2)
Huh? It misses the tools.jar from Sun’s JDK.
Murders – Mr. profile “default-tools” & Mr. Sun Micro the JDK
I soon dig out that it is the struts2-core artifact has a dependency on Sun’s tools.jar. A profile named “default-tools.jar” declared the dependency on the tools.jar, which is activated when you are running the maven operation with Sun’s JDK. This is what you can see from struts2-core’s pom.
<profile>
<id>default-tools.jar</id>
<activation>
<property>
<name>java.vendor</name>
<value>Sun Microsystems Inc.</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.5.0</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
</profile>
Yet strange enough, I had no problem running the build with my command prompt. It only matters when running in Eclipse. To be exact, there was no problem when I manually triggered the building process by “Run as Maven2 Build” with the pom. But when Eclipse builds the project automatically, say after a clean, the error pops.
Adding the tools.jar to Eclipse’s JDK runtime does not help. Nonetheless this does look like a good practice so I give it up.
So what have went wrong? The profile try to look up the tools.jar by back stepping from the directory java.home, where it is the home directory of running Java process automatically deduced and set by Maven. If java.home points to a JDK, the path works as JDK comes with a tools.jar in the lib/ folder. But if java.home points to a JRE instead, the path should fail as JRE doesn’t bring along the tools.jar. When I start Eclipse, I could have started it by either a JRE or a JDK as I simply doubled clicked the shortcut to it on my desktop. The remaining problem is, isn’t it Eclipse is running the Maven 2 Builder with my configured JDK in the project? So I make the shots.
Starting Eclipse with -vm Option
The configuration free classic way to start Eclipse with desired VM.
$>eclipse -vm "C:\Program Files\Java\jdk1.6.0_01\bin"
Wow! It works. Okay, give it another shot.
Making JDK/bin the First Element in %PATH%
$>set PATH=C:\Program Files\Java\jdk1.6.0_01\bin;%PATH%
$>eclipse
Jesus! it works again.
Conclusion?
It looks like the when Eclipse is told to call the maven build manually with a pom.xml it, it executes with the configured JDK’s path. But when it comes to execute the Maven 2 Builder, it uses the Java process which starts the Eclipse instead. So if the Eclipse’s started with a Sun Micro JRE, it misses the tools.jar for struts2-core. Other JDK/JRE doesn’t matter, however, as the tools.jar or equivalent are usually on the classpath already.
Is it a behavior of Eclipse or just that of the M2Eclipse plug-in? I haven’t figured out yet. May be I just messed all the things up by accident (or luck). If anyone know what’s really inside, let me know
Missing dependency tools.jar
8/13/07 5:58:51 PM CST: Missing:
1) com.sun:tools:jar:1.5.0
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=com.sun -DartifactId=tools \
-Dversion=1.5.0 -Dpackaging=jar -Dfile=/path/to/file
Path to dependency:
1) tutorial:tutorial4:war:1.0-SNAPSHOT
2) org.apache.struts:struts2-core:jar:2.0.5
3) com.sun:tools:jar:1.5.0
1 required artifact is missing.
for artifact:
tutorial:tutorial4:war:1.0-SNAPSHOT
from the specified remote repositories:
central (http://repo1.maven.org/maven2)
Huh? It misses the tools.jar from Sun’s JDK.
Murders – Mr. profile “default-tools” & Mr. Sun Micro the JDK
I soon dig out that it is the struts2-core artifact has a dependency on Sun’s tools.jar. A profile named “default-tools.jar” declared the dependency on the tools.jar, which is activated when you are running the maven operation with Sun’s JDK. This is what you can see from struts2-core’s pom.
<profile>
<id>default-tools.jar</id>
<activation>
<property>
<name>java.vendor</name>
<value>Sun Microsystems Inc.</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.5.0</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
</profile>
Yet strange enough, I had no problem running the build with my command prompt. It only matters when running in Eclipse. To be exact, there was no problem when I manually triggered the building process by “Run as Maven2 Build” with the pom. But when Eclipse builds the project automatically, say after a clean, the error pops.
Adding the tools.jar to Eclipse’s JDK runtime does not help. Nonetheless this does look like a good practice so I give it up.
So what have went wrong? The profile try to look up the tools.jar by back stepping from the directory java.home, where it is the home directory of running Java process automatically deduced and set by Maven. If java.home points to a JDK, the path works as JDK comes with a tools.jar in the lib/ folder. But if java.home points to a JRE instead, the path should fail as JRE doesn’t bring along the tools.jar. When I start Eclipse, I could have started it by either a JRE or a JDK as I simply doubled clicked the shortcut to it on my desktop. The remaining problem is, isn’t it Eclipse is running the Maven 2 Builder with my configured JDK in the project? So I make the shots.
Starting Eclipse with -vm Option
The configuration free classic way to start Eclipse with desired VM.
$>eclipse -vm "C:\Program Files\Java\jdk1.6.0_01\bin"
Wow! It works. Okay, give it another shot.
Making JDK/bin the First Element in %PATH%
$>set PATH=C:\Program Files\Java\jdk1.6.0_01\bin;%PATH%
$>eclipse
Jesus! it works again.
Conclusion?
It looks like the when Eclipse is told to call the maven build manually with a pom.xml it, it executes with the configured JDK’s path. But when it comes to execute the Maven 2 Builder, it uses the Java process which starts the Eclipse instead. So if the Eclipse’s started with a Sun Micro JRE, it misses the tools.jar for struts2-core. Other JDK/JRE doesn’t matter, however, as the tools.jar or equivalent are usually on the classpath already.
Is it a behavior of Eclipse or just that of the M2Eclipse plug-in? I haven’t figured out yet. May be I just messed all the things up by accident (or luck). If anyone know what’s really inside, let me know
本文探讨了在Eclipse中使用Maven构建Struts2项目时遇到的tools.jar缺失问题。通过分析struts2-core的pom文件,发现其依赖于Sun JDK的tools.jar,并介绍了如何通过配置Eclipse的启动参数来解决此问题。
3万+

被折叠的 条评论
为什么被折叠?



