Maven无法使用rt.jar进行编译 [英] Maven can't compile using rt.jar
问题描述
我的项目使用sun.security.tools.keytool
在JDK 1.8下生成证书,并且可以在rt.jar
中找到此软件包.根据关于依赖机制的介绍,系统依赖,我可以将rt.jar
作为依赖项添加到我的项目中:
My project uses sun.security.tools.keytool
to generate certificate under JDK 1.8 and this package can be found in rt.jar
. According to Introduction to the Dependency Mechanism, System Dependencies, I can add rt.jar
as a dependency to my project:
<dependency>
<groupId>sun.jdk</groupId>
<artifactId>rt.jar</artifactId>
<version>1.8</version>
<scope>system</scope>
<systemPath>${java.home}/lib/rt.jar</systemPath>
</dependency>
我很确定Maven找到了这个jar文件.但是,当我导入sun.security.tools.keytool.Main
时,它仍然会产生错误.而且,最奇怪的是,如果我将rt.jar
复制到某个地方并在pom.xml
中填充其路径,它就可以工作!一旦我切换回原来的rt.jar
,它就会失败!
I'm pretty sure Maven found this jar file. However when I import sun.security.tools.keytool.Main
, it still generates an error. Moreover, the most strange thing is if I copy rt.jar
into someplace and fill its path in pom.xml
, it works! As soon as I switch back to use the original rt.jar
, it fails!
谁能告诉我这怎么发生?
Can anyone tell me how could this happen?
推荐答案
我创建了一个Maven项目并将您问题的<dependency>
添加到其POM中.
I created a Maven project and added the <dependency>
of your question to its POM.
首先我得到:
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] .../SO-31353565/src/main/java/igb/so/SO31353565.java:[6,34]
package sun.security.tools.keytool does not exist
[ERROR] .../SO-31353565/src/main/java/igb/so/SO31353565.java:[12,50]
cannot find symbol
symbol: variable Main
location: class igb.so.SO31353565
Then, according to Cannot find symbol (CertAndKeyGen) with JDK8, I added:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<fork>true</fork>
<compilerArgument>-XDignore.symbol.file</compilerArgument>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
到POM,编译成功.
这篇关于Maven无法使用rt.jar进行编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!