菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
26
0

maven报 Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.0:compile(defalut-compile) on project 项目名称:No such compile 'javac'

原创
05/13 14:22
阅读数 16339

     这个问题纠结了一天,在另外一个电脑是正常的,但是从服务器下载下来到另外一个电脑的时候却出现了如下图问题

看到javac大家都会想到是编译出现问题,而本地的配置如下图所示: 

看着配置都是一致的,会是哪里的问题呢?经网上咨询有个大神说是可能是maven没有配置指定的jdk原因,原因如下:

  maven是个项目管理工具,如果我们不告诉它我们的代码要使用什么样的jdk版本编译的话,它就会用maven-compiler-plugin默认的jdk版本来进行处理,这样就容易出现版本不匹配的问题,以至于可能导致编译不通过的问题。为了处理这一种情况的出现,在构建maven项目的时候,我习惯性第一步就是配置maven-compiler-plugin插件。解决办法:

     在pom.xml中指定使用的版本 1 <build>

 2         <plugins>
 3             <plugin>
 4                     <groupId>org.apache.maven.plugins</groupId>
 5                     <artifactId>maven-compiler-plugin</artifactId>
 <!-- 使用3.5.1也是正确 不知道为啥 如果是3.0就是错误的,但是maven里面也有3.0的版本,可能跟我电脑安装的maven版本有关,本地按照maven版本为3.0.5 -->
 6             <version>3.1</version>     
 7                     <configuration>
 8                         <defaultLibBundleDir>lib</defaultLibBundleDir>
 9                         指定高版本的源码和编译后的字节码文件
10                         <source>1.6</source>
11                         <target>1.6</target>
12                         <optimize>true</optimize>
13                         <debug>true</debug>
14                         <showDeprecation>true</showDeprecation>
15                         <showWarnings>true</showWarnings>
16                         <encoding>UTF-8</encoding>
17                     </configuration>
18                 </plugin>
19             
20         </plugins>
21     </build>

经过指定后,电脑可以正常运行了。

 

 

问题2:

1 [WARNING] 
2 [WARNING] Some problems were encountered while building the effective model for com.xxx.xxx:xxxx:jar:0.0.1-SNAPSHOT 
3 [WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 72, column 12 
4 [WARNING] 
5 [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build. 
6 [WARNING] 
7 [WARNING] For this reason, future Maven versions might no longer support building such malformed projects. 
8 [WARNING] 

对照官网用法:http://maven.apache.org/plugins/maven-compiler-plugin/usage.html 

起初配置:

 1 <plugins>  
 2     <plugin>  
 3         <artifactId>maven-compiler-plugin</artifactId>  
 4         <configuration>  
 5             <source>1.6</source>  
 6             <target>1.6</target>  
 7             <encoding>UTF-8</encoding>  
 8         </configuration>  
 9     </plugin>  
10 </plugins> 

该问题解决办法是需要置顶maven版本,解决办法:

 1 <plugins>  
 2         <plugin>  
 3             <artifactId>maven-compiler-plugin</artifactId>  
 4             <version>3.0</version>  
 5             <configuration>  
 6                 <source>1.6</source>  
 7                 <target>1.6</target>  
 8                 <encoding>UTF-8</encoding>  
 9             </configuration>  
10         </plugin>  
11     </plugins>  

 

发表评论

0/200
26 点赞
0 评论
收藏