文档章节

maven 打包独立可运行jar

Oscarfff
 Oscarfff
发布于 2016/02/13 19:09
字数 629
阅读 96
收藏 3

Creating a .jar Deployment Package Using Maven and Eclipse IDE (Java)

This section shows how to package your Java code into a deployment package using Eclipse IDE and Maven plugin for Eclipse.

Topics

Before You Begin

Install the Maven Plugin for Eclipse.

  1. Start Eclipse. From the Help menu in Eclipse, choose Install New Software.

  2. In the Install window, type http://download.eclipse.org/technology/m2e/releases in the Work with: box, and choose Add.

  3. Follow the steps to complete the setup.

Step 1: Create and Build a Project

In this step, you start Eclipse and create a Maven project. You will add the necessary dependencies, and build the project. The build will produce a .jar, which is your deployment package.

  1. Create a new Maven project in Eclipse.

    • Group Id: doc-examples

    • Artifact Id: lambda-java-example

    • Version: 0.0.1-SNAPSHOT

    • Packaging: jar

    • Name: lambda-java-example

    1. From the File menu, choose New, and then choose Project.

    2. In the New Project window, choose Maven Project.

    3. In the New Maven Project window, choose Create a simple project, and leave other default selections.

    4. In the New Maven ProjectConfigure project windows, type the following Artifact information:

  2. Add the aws-lambda-java-core dependency to the pom.xml file.

    It provides definitions of the RequestHandlerRequestStreamHandler, and Context interfaces. This allows you to compile code that you can use with AWS Lambda.

    1. Open the context (right-click) menu for the pom.xml file, choose Maven, and then choose Add Dependency.

    2. In the Add Dependency windows, type the following values:

      Group Id: com.amazonaws

      Artifact Id: aws-lambda-java-core

      Version: 1.1.0

      Caution

      If you are following other tutorial topics in this guide, the specific tutorials might require you to add more dependencies. Make sure to add those dependencies as required.

  3. Add Java class to the project.

    • Packageexample

    • NameHello

      Caution

      If you are following other tutorial topics in this guide, the specific tutorials might recommend different package name or class name.

    1. Open the context (right-click) menu for the src/main/java subdirectory in the project, choose New, and then choose Class.

    2. In the New Java Class window, type the following values:

    3. Add your Java code. If you are following other tutorial topics in this guide, add the provided code.

  4. Build the project.

    Open the context (right-click) menu for the project in Package Explorer, choose Run As, and then chooseMaven Build .... In the Edit Configuration window, type package in the Goals box.

    Note

    The resulting .jar, lambda-java-example-0.0.1-SNAPSHOT.jar, is not the final standalone .jar that you can use as your deployment package. In the next step, you add the Apache maven-shade-plugin to create the standalone .jar. For more information, go to Apache Maven Shade Plugin.

  5. Add the maven-shade-plugin plugin and rebuild.

    The maven-shade-plugin will take artifacts (jars) produced by the package goal (produces customer code .jar), and created a standalone .jar that contains the compiled customer code, and the resolved dependencies from the pom.xml.

    • Group Id: org.apache.maven.plugins

    • Artifact Id: maven-shade-plugin

    • Version: 2.3

    1. Open the context (right-click) menu for the project, choose Run As, and then choose Maven build ....

    2. In the Edit Configuration windows, type package shade:shade in the Goals box.

    3. Choose Run.

      You can find the resulting standalone .jar (that is, your deployment package), in the /targetsubdirectory.

      Open the context (right-click) menu for the /target subdirectory, choose Show In, choose System Explorer, and you will find the lambda-java-example-0.0.1-SNAPSHOT.jar.

    4. Open the context (right-click) menu for the pom.xml file, choose Maven, and then choose Add Plugin.

    5. In the Add Plugin window, type the following values:

    6. Now build again.

      This time we will create the jar as before, and then use the maven-shade-plugin to pull in dependencies to make the standalone .jar.


本文转载自:http://docs.aws.amazon.com/lambda/latest/dg/java-create-jar-pkg-maven-and-eclipse.html

共有 人打赏支持
Oscarfff
粉丝 72
博文 815
码字总数 96913
作品 0
崇明
后端工程师
maven打包时加入依赖包及加入本地依赖包

maven打包的时候默认是不加入依赖的jar包的,所以想打出一个独立的可运行jar包的话直接mvn clean install package是不行的。需要略改动下pom文件,加入如下plugin <build><sourceDirectory>...

王小明123
2014/05/18
0
3
maven 打包可执行jar的方法

在这之前,我自己找了点maven的东西添加进来 Maven内置变量说明:${basedir} 项目根目录${project.build.directory} 构建目录,缺省为target${project.build.outputDirectory} 构建过程输出目...

十月阳光
2016/01/22
4.7K
0
maven 生命周期和常用命令

一、Maven的生命周期 Maven的生命周期就是对所有的构建过程进行抽象和统一。包含了项目的清理、初始化、编译、测试、打包、集成测试、验证、部署和站点生成等几乎所有的构建步骤。 Maven的生...

诗和_远方
2017/03/29
0
0
Spring Cloud(三) 把Spring Cloud 打成jar包 war包部署到server上

一、前言 怎样把已经开发的spring cloud 项目进行打包部署,其实过程和spring boot 的是一样的。经过摸索之后,才发现其实spring cloud 的每个Project 可以直接打成jar包运行,因为里面自带了...

上善若水
2017/09/05
0
0
SpringBoot 学习:(一)快速搭建项目

一、简介 从 Spring Boot 项目名称中的 Boot 可以看出来,Spring Boot 的作用在于创建和启动新的基于 Spring 框架的项目。它的目的是帮助开发人员很容易的创建出独立运行和产品级别的基于 Sp...

Element0506
2015/07/25
0
0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

JS:异步 - 面试惨案

为什么会写这篇文章,很明显不符合我的性格的东西,原因是前段时间参与了一个面试,对于很多程序员来说,面试时候多么的鸦雀无声,事后心里就有多么的千军万马。去掉最开始毕业干了一年的Jav...

xmqywx
今天
0
0
Win10 64位系统,PHP 扩展 curl插件

执行:1. 拷贝php安装目录下,libeay32.dll、ssleay32.dll 、 libssh2.dll 到 C:\windows\system32 目录。2. 拷贝php/ext目录下, php_curl.dll 到 C:\windows\system32 目录; 3. p...

放飞E梦想O
今天
0
0
谈谈神秘的ES6——(五)解构赋值【对象篇】

上一节课我们了解了有关数组的解构赋值相关内容,这节课,我们接着,来讲讲对象的解构赋值。 解构不仅可以用于数组,还可以用于对象。 let { foo, bar } = { foo: "aaa", bar: "bbb" };fo...

JandenMa
今天
1
0
OSChina 周一乱弹 —— 有人要给本汪介绍妹子啦

Osc乱弹歌单(2018)请戳(这里) 【今日歌曲】 @莱布妮子 :分享水木年华的单曲《中学时代》@小小编辑 手机党少年们想听歌,请使劲儿戳(这里) @须臾时光:夏天还在做最后的挣扎,但是晚上...

小小编辑
今天
21
5
centos7安装redis及开机启动

配置编译环境: sudo yum install gcc-c++ 下载源码: wget http://download.redis.io/releases/redis-3.2.8.tar.gz 解压源码: tar -zxvf redis-3.2.8.tar.gz 进入到解压目录: cd redis-3......

hotsmile
今天
2
0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

返回顶部
顶部