为什么使用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>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值