maven 使用 问题记录

本文详细介绍了在Maven项目中配置Java编译器版本、管理依赖部署的方法,包括如何在POM文件中设置源目标版本、使用maven-compiler-plugin与maven-surefire-plugin插件进行编译与测试跳过,以及依赖范围(compile、provided、runtime、test、system)的理解。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Java compiler level does not match the version of the installed Java project facet

Assuming that you are using the m2e plugin in Eclipse, you'll need to specify the source and targetversions as 1.6 for maven-compiler-plugin. m2e uses these values to determine the project's Java compiler level. A snippet of the POM is shown below:

<build>
  <plugins>
    <plugin>
      <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
    </plugin>
  </plugins>
</build>

Alternatively, you can specify the maven.compiler.source and maven.compiler.targetproperties with values of 1.6, that happen to be the equivalent:

<properties>
    <maven.compiler.target>1.6</maven.compiler.target>
    <maven.compiler.source>1.6</maven.compiler.source>
</properties>


 http://stackoverflow.com/questions/7715260/java-compiler-level-does-not-match-the-version-of-the-installed-java-project-fac 

在POM 4中,<dependency>中还引入了<scope>,它主要管理依赖的部署。 
    * compile,缺省值,适用于所有阶段,会随着项目一起发布。 
    * provided,类似compile,期望JDK、容器或使用者会提供这个依赖。如servlet.jar。 
    * runtime,只在运行时使用,如JDBC驱动,适用运行和测试阶段。 
    * test,只在测试时使用,用于编译和运行测试代码。不会随项目发布。 
    * system,类似provided,需要显式提供包含依赖的jar,Maven不会在Repository中查找它。

官方文档: http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html 


Maven编译打包时如何忽略测试用例

如果想跳过测试阶段,可用:
mvn package -DskipTests

想临时性跳过测试代码的编译,可用:
mvn package -Dmaven.test.skip=true
maven.test.skip同时控制maven-compiler-plugin和maven-surefire-plugin两个插件的行为,即跳过编译,又跳过测试。

http://cwj158.iteye.com/blog/1528537

Maven最佳实践:划分模块 http://juvenshun.iteye.com/blog/305865 


转载于:https://my.oschina.net/cedo/blog/294437

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值