首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Eclipse开发 >

为什么使用rt.jar的内部类,在eclipse运行没有关问题,而在mvn编译的时候失败呢

2013-12-26 
为什么使用rt.jar的内部类,在eclipse运行没问题,而在mvn编译的时候失败呢Suns *java compiler* detects w

为什么使用rt.jar的内部类,在eclipse运行没问题,而在mvn编译的时候失败呢

Sun's *java compiler* detects when a special "internal" class is being accessed, and refuses to import the class. Eclipse uses a different compiler which presumably does not have this check. Maven just uses the javac compiler available in the system execution path. Therefore the problem is nothing to do with Maven at all. It's the compiler that maven is invoking which is refusing to compile the source. I can't see any public flags in the javac commandline to disable this "blocking" of internal access, so unless you want to avoid using Sun's javac compiler you'll just have to avoid using this internal class. 

为什么使用rt.jar的内部类,在eclipse运行没问题,而在mvn编译的时候失败呢?

?

maven 编译的时候,默认使用jdk的javac进行编译,javac本身是不支持访问内部类的

?

而在eclipse中编译没问题,也可以运行成功,那是因为在eclipse中它的编译器是eclipse自己写的

并没做这样的限制

?

所以把mvn的编译器换成eclipse的实现应该就ok了

<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.1</version><configuration> <compilerId>eclipse</compilerId><source>1.6</source><target>1.6</target><optimize>true</optimize> <verbose>false</verbose> <useIncrementalCompilation>false</useIncrementalCompilation><showWarnings>false</showWarnings>          <showDeprecation>false</showDeprecation> <debug>false</debug> </configuration><dependencies>  <dependency>                        <groupId>org.codehaus.plexus</groupId>                        <artifactId>plexus-compiler-eclipse</artifactId><!---2.2  org.eclipse.jdt.core-3.8.1.v20120531-0637 --><!---2.1  org.eclipse.jdt.core-3.8.1.v20120531-0637 -->                         <version>2.2</version>                    </dependency> </dependencies></plugin>

?

热点排行