前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Maven 项目配置使用备忘录

Maven 项目配置使用备忘录

作者头像
耕耘实录
发布2023-07-24 14:38:24
1590
发布2023-07-24 14:38:24
举报
文章被收录于专栏:耕耘实录耕耘实录
  1. 创建 Maven 项目:
代码语言:javascript
复制
 mvn archetype:generate -DgroupId=com.ivandu -DartifactId=cmaimms -DarchetypeArtifactImaven-archetype-quickstart -DinteractiveMode=false

命令解释:

  • -DgroupId 组织Id(项目包名)。
  • -DartifactId ArtifactId(项目名称或者模块名称)。
  • -DarchetypeArtifactId 项目骨架。
  • -DinteractiveMode 是否使用交互模式。
  1. “File encoding has not been set, using platform encoding UTF-8” 问题解决:

IDE 字符编码设置为:UTF-8, IDEA 自定义环境加入:

代码语言:javascript
复制
-Dfile.encoding=utf-8

项目 pom.xml 加入:

代码语言:javascript
复制
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  1. “No goals have been specified for this build.” 问题解决:

项目 pom.xml 加入:

代码语言:javascript
复制
<build>
    <defaultGoal>compile</defaultGoal>
</build>
  1. “[ERROR] 不再支持源选项 5。请使用 6 或更高版本。[ERROR] 不再支持目标选项 1.5。请使用 1.6 或更高版本。” 问题解决:
代码语言:javascript
复制
<properties>
    <java.version>11</java.version>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
</properties>
  1. mvn spring-boot:run 报 “No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?” 错,解决如下:

在项目 pom.xml build 节点内加入:

代码语言:javascript
复制
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.8.1</version>
  <configuration>
    <verbose>true</verbose>
    <fork>true</fork>
    <executable>D:\Tools\Java\jdk-11.0.12.7-hotspot\bin\javac.exe</executable>
  </configuration>
</plugin>
  1. 一些常用配置:
代码语言:javascript
复制
<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
</properties>
  1. 指定 JDK 版本、字符集配置:
代码语言:javascript
复制
<profile>
    <id>jdk-11</id>
    <activation>
        <activeByDefault>true</activeByDefault>
        <jdk>11</jdk>
    </activation>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <maven.compiler.compilerVersion>11</maven.compiler.compilerVersion>
    </properties>
</profile>
  1. Maven 阿里云公共仓库:
代码语言:javascript
复制
<mirror>
    <id>aliyunmaven</id>
    <mirrorOf>*</mirrorOf>
    <name>阿里云公共仓库</name>
    <url>https://maven.aliyun.com/repository/public</url>
</mirror>
  1. 无法读取配置文件,可以加入如下内容:
代码语言:javascript
复制
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
                <source>11</source>
                <target>11</target>
            </configuration>
        </plugin>
    </plugins>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.xml</include>
                <include>**/*.properties</include>
            </includes>
            <filtering>false</filtering>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.*</include>
                <include>**/*.properties</include>
            </includes>
            <filtering>false</filtering>
        </resource>
    </resources>
</build>
  1. Maven scope 元素用于指定依赖库起作用的范围。该元素可指定如下值:

➢ compile:默认的范围,编译、测试、打包时需要。 ➢ provided:表示容器会在运行时提供。 ➢ runtime:表示编译时不需要,但测试和运行时需要,最终打包时会包含进来。 ➢ test:只用于测试阶段。 ➢ system:与provided类似,但要求该JAR是系统自带的。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2023-07-11,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
腾讯云服务器利旧
云服务器(Cloud Virtual Machine,CVM)提供安全可靠的弹性计算服务。 您可以实时扩展或缩减计算资源,适应变化的业务需求,并只需按实际使用的资源计费。使用 CVM 可以极大降低您的软硬件采购成本,简化 IT 运维工作。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档