Maven编译Java项目
Spring在线参考文档: http://spring.io/guides/gs/maven/
下载安装
Downloadand unzip the source repository for this guide, or clone it using Git:
git clone https://github.com/spring-guides/gs-maven.gitcd into
gs-maven/initialJump ahead to [initial].
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项目的更多相关文章
- 使用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- ...
- 使用maven编译Java项目
摘要: 综述 本文演示了用Maven编译Java项目 需要 时间:15分钟 文本编辑器或者IDE JDK 6 或者更高版本 创建项目 本例主要为了展示Maven,所以Java的项目力求简单. 创建项目 ...
- Jenkins 通过 maven 构建编译 JAVA 项目环境
Jenkins 通过maven 构建编译 JAVA 项目环境 官网下载合适Jenkins版本包: 1.jenkins http://mirrors.jenkins.io/war-stable/ 2.J ...
- maven构建java项目、web项目
maven构建java项目.web项目 一.mvn构建web项目 1安装mvn(包括path) 2命令:mvn archetype:create -DgroupId=cn.edu.sdau.neat ...
- maven 学习---使用Maven创建Java项目
在本教程中,我们将向你展示如何使用 Maven 来创建一个 Java 项目,导入其到Eclipse IDE,并打包 Java 项目到一个 JAR 文件. 所需要的工具: Maven 3.3.3 Ecl ...
- 《Maven在Java项目开发中的应用》论文笔记(十七)
标题:Maven在Java项目开发中的应用 一.基本信息 时间:2019 来源:山西农业大学 关键词:Maven:Java Web:仓库:开发人员:极限编程; 二.研究内容 1.Maven 基本原理概 ...
- appium + maven +jenkins 基本入门之二 新建maven 的java项目
1: 下载maven : 1.0 :设置maven的环境变量: 1.1: 设置maven本地仓库: 在下载好的maven文件夹找到 apache-maven-3.3.9/conf 文件夹下的setti ...
- 使用 Gradle 编译 Java 项目时报错: Could not find Tools.jar
在使用Android studio进行编译成jar的时候,遇到Gradle 编译错误,听前辈们说是jdk的版本不对,于是乎就更新了一下jdk, 然而可能是我重新安装jdk的时候改变了安装路径, 在pr ...
- ANT入门&用ANT编译java项目
第一次接触ant是15年在无锡某软件公司实习时,当时的项目是由多个模块组成,开发分成模块开发的几个小组.为了提高开发效率,采用这种编译项目的方法. 最近接触到flex项目,采用eclipse自动编译的 ...
随机推荐
- STM32之关闭JTAG
1.有些时候不想用JTAG口(而用SWJ在线调试),把JTAG暂用的IO通过remap出来使用 2.比如48 pin的STM32F103CBT6单片机: GPIO_PinRemapConfig(GPI ...
- Office365学习笔记—创建WikiPage
1,项目有个需求:项目表每更新一次,就把跟该项目有关的任务创建一个静态页(历史版本功能)! 注意事项:需要在页面上拖一个ContentEditer!将代码放在ContentEditer里面,因为我试过 ...
- Java Bean与Map之间相互转化的实现
目录树 概述 Apache BeanUtils将Bean转Map Apache BeanUtils将Map转Bean 理解BeanUtils将Bean转Map的实现之手写Bean转Map 概述 Apa ...
- UIView常用的一些方法setNeedsDisplay和setNeedsLayout
1,UIView的setNeedsDisplay和setNeedsLayout方法 首先两个方法都是异步执行的.而setNeedsDisplay会调用自动调用drawRect方法,这样可以拿到 UI ...
- JS中的“==”与强制类型转换
JavaScript中有“==”与“===”,那么他们有何区别呢? 对于基本数据类型, === (!==)只有当两个变量的类型和值都相等时,才返回true:而 == (!=)则会对变量进行强制类型转 ...
- C++笔记006:关于类的补充
原创笔记,转载请注明出处! 点击[关注],关注也是一种美德~ 关于类的补充: 类是一个数据类型(固定大小内存块的别名),定义一个类,是一个抽象的概念,不会给你分配内存,用数据类型定义变量的时候,才会分 ...
- pt-online-schema-change在线修改表结构
工具简介 pt-osc模仿MySQL内部的改表方式进行改表,但整个改表过程是通过对原始表的拷贝来完成的,即在改表过程中原始表不会被锁定,并不影响对该表的读写操作.首先,osc创建与原始表相同的不包含数 ...
- 安装psutil时提示缺少python.h头文件(作记录)
通过pip或者源码安装psutil,都会提示缺少python.h头文件,错误提示如下: ... psutil/_psutil_common.c:9:20: fatal error: Python.h: ...
- hql返回数值
public int getCountUser() throws ParseException { Session hSession = sessionFactory.getCurrentSessio ...
- Flink基本概念
Flink基本概念 1.The history of Flink? 2.What is Flink? Apache Flink是一个开源的分布式.高性能.高可用.准确的流处理框架,主要由Java代码实 ...