maven编译时找不到com.sun包的原因与解决方法

maven编译时找不到com.sun包.

原因:javac uses a special symbol table that does not include all Sun-proprietary classes. When javac is compiling code it doesn't link against rt.jar by default. Instead it uses special symbol file lib/ct.sym with class stubs.

大意是:javac在编译时,并不引用 rt.jar,用的是一个特别的symbol table(lib/ct.sym),这个symbol table不包含所有的sun包的类;

解决方法:使用 -XDignore.symbol.file,这样javac编译时就会引用rt.jar

javac -XDignore.symbol.file

maven的pom.xml中增加配置:

<plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <compilerArgs>
                    <arg>-XDignore.symbol.file</arg>
                </compilerArgs>
                <fork>true</fork>
            </configuration>
            ...

猜你喜欢

转载自hzwei206.iteye.com/blog/2366531