Spring在线参考文档: http://spring.io/guides/gs/maven/

下载安装

Once you have downloaded the zip file, unzip it to your computer. Then add the bin folder to your path.

检查mvn是否安装成功: mvn -v

Apache Maven 3.3. (bb52d8502b132ec0a5a3f4c09453c07478323dc5; --10T16::+:)
Maven home: /home/dsyer/Programs/apache-maven
Java version: 1.8.0_152, vendor: Azul Systems, Inc.
Java home: /home/dsyer/.sdkman/candidates/java/8u152-zulu/jre
Default locale: en_GB, platform encoding: UTF-
OS name: "linux", version: "4.15.0-36-generic", arch: "amd64", family: "unix"

配置项目文件

mkdir -p src/main/java/hello

src/main/java/hello/HelloWorld.java

package hello;

public class HelloWorld {
public static void main(String[] args) {
Greeter greeter = new Greeter();
System.out.println(greeter.sayHello());
}
}

src/main/java/hello/Greeter.java

package hello;

public class Greeter {
public String sayHello() {
return "Hello world!";
}
}

pom.xml 与src目录平级

  • <modelVersion>. POM model version (always 4.0.0).

  • <groupId>. Group or organization that the project belongs to. Often expressed as an inverted domain name.

  • <artifactId>. Name to be given to the project’s library artifact (for example, the name of its JAR or WAR file).

  • <version>. Version of the project that is being built.

  • <packaging> - How the project should be packaged. Defaults to "jar" for JAR file packaging. Use "war" for WAR file packaging.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>org.springframework</groupId>
<artifactId>gs-maven</artifactId>
<packaging>jar</packaging>
<version>0.1.0</version> <properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties> <build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>hello.HelloWorld</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
# This will run Maven, telling it to execute the compile goal
mvn compile

# The package goal will compile your Java code, run any tests, and finish by packaging the code up in a JAR file within the target directory

mvn package

# The install goal will compile, test, and package your project’s code and then copy it into the local dependency repository, ready for another project to reference it as a dependency

mvn install

# run tests unit

mvn test

dependencies 声明依赖关系

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>org.springframework</groupId>
<artifactId>gs-maven</artifactId>
<packaging>jar</packaging>
<version>0.1.0</version> <properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties> <dependencies>
<!-- tag::joda[] -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.2</version>
</dependency>
<!-- end::joda[] -->
<!-- tag::junit[] -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- end::junit[] -->
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>hello.HelloWorld</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build> </project>

Maven编译Java项目的更多相关文章

  1. 使用maven编译Java项目 http://www.tuicool.com/articles/YfIfIrq

    使用maven编译Java项目 时间 2014-07-17 17:42:37  Way Lau's Blog 原文  http://www.waylau.com/build-java-project- ...

  2. 使用maven编译Java项目

    摘要: 综述 本文演示了用Maven编译Java项目 需要 时间:15分钟 文本编辑器或者IDE JDK 6 或者更高版本 创建项目 本例主要为了展示Maven,所以Java的项目力求简单. 创建项目 ...

  3. Jenkins 通过 maven 构建编译 JAVA 项目环境

    Jenkins 通过maven 构建编译 JAVA 项目环境 官网下载合适Jenkins版本包: 1.jenkins http://mirrors.jenkins.io/war-stable/ 2.J ...

  4. maven构建java项目、web项目

    maven构建java项目.web项目 一.mvn构建web项目 1安装mvn(包括path) 2命令:mvn archetype:create -DgroupId=cn.edu.sdau.neat ...

  5. maven 学习---使用Maven创建Java项目

    在本教程中,我们将向你展示如何使用 Maven 来创建一个 Java 项目,导入其到Eclipse IDE,并打包 Java 项目到一个 JAR 文件. 所需要的工具: Maven 3.3.3 Ecl ...

  6. 《Maven在Java项目开发中的应用》论文笔记(十七)

    标题:Maven在Java项目开发中的应用 一.基本信息 时间:2019 来源:山西农业大学 关键词:Maven:Java Web:仓库:开发人员:极限编程; 二.研究内容 1.Maven 基本原理概 ...

  7. appium + maven +jenkins 基本入门之二 新建maven 的java项目

    1: 下载maven : 1.0 :设置maven的环境变量: 1.1: 设置maven本地仓库: 在下载好的maven文件夹找到 apache-maven-3.3.9/conf 文件夹下的setti ...

  8. 使用 Gradle 编译 Java 项目时报错: Could not find Tools.jar

    在使用Android studio进行编译成jar的时候,遇到Gradle 编译错误,听前辈们说是jdk的版本不对,于是乎就更新了一下jdk, 然而可能是我重新安装jdk的时候改变了安装路径, 在pr ...

  9. ANT入门&用ANT编译java项目

    第一次接触ant是15年在无锡某软件公司实习时,当时的项目是由多个模块组成,开发分成模块开发的几个小组.为了提高开发效率,采用这种编译项目的方法. 最近接触到flex项目,采用eclipse自动编译的 ...

随机推荐

  1. 【2017001】IList转DataTable、DataTable转IList

    IList转DataTable.DataTable转IList using System; using System.Collections.Generic; using System.Compone ...

  2. 能成为一名合格的Java架构师

    原文地址:http://www.dalbll.com/Group/Topic/ArchitecturedDesign/4943 俗话说“没有见过好程序,怎么可能写出好程序”,同样,也可以说“不了解架构 ...

  3. Unity 游戏框架搭建 2018 (二) 单例的模板与最佳实践

    Unity 游戏框架搭建 2018 (二) 单例的模板与最佳实践 背景 很多开发者或者有经验的老手都会建议尽量不要用单例模式,这是有原因的. 单例模式是设计模式中最简单的也是大家通常最先接触的一种设计 ...

  4. OC中property方法的使用

    我们直入主题,关于property方法,我们先来了解一下相关的知识,首先是成员变量,实例变量,属性变量. 我们定义一个类来看一下 @interface Person :NSObject{ NSInte ...

  5. webstorm如何支持markdown

    首先安装markdown 插件 第一个即可.

  6. UCanCode发布升级E-Form++可视化源码组件库2018全新版 !

    2018年. 成都 UCanCode发布升级E-Form++可视化源码组件库2018全新版 ! --- 全面性能提升,UCanCode有史以来最强大的版本发布! E-Form++可视化源码组件库企业版 ...

  7. 解决 LLVM 错误 fatal error: ‘csignal’ file not found

    /Users/exchen/Downloads/Unity-iPhone/Classes/main.mm:3:10: fatal error: ‘csignal’ file not found#inc ...

  8. 本人擅长Ai、Fw、Fl、Br、Ae、Pr、Id、Ps等

    本人擅长Ai.Fw.Fl.Br.Ae.Pr.Id.Ps等软件的安装与卸载,精通CSS.JavaScript.PHP.ASP.C.C++.C#.Java.Ruby.Perl.Lisp.python.Ob ...

  9. linux搭建的LNMP环境下的mysql授权远程连接

    用phpstudy搭建的lnmp环境下mysql授权远程连接 简单高效 这是因为mysql 里的优先级不是所有人(提前检查防火墙是关闭状态)1.使用phpstudy安装的mysql没有放置到可以直接调 ...

  10. [转]关于sdk更新Android SDK Tools 25.3.1版本后使用sdk manager闪退

    昨天这两个manager还工作正常,今天更新了一下,发现不可用了,运行avd manager和sdk manager没反应,搜了好多文章,然后看到了下这篇文章<关于sdk更新Android SD ...