文档章节

maven 打包独立可运行jar

Oscarfff
 Oscarfff
发布于 2016/02/13 19:09
字数 629
阅读 99
收藏 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
粉丝 73
博文 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
SpringBoot 学习:(一)快速搭建项目

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

Element0506
2015/07/25
0
0
Spring Cloud(三) 把Spring Cloud 打成jar包 war包部署到server上

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

上善若水
2017/09/05
0
0

没有更多内容

加载失败,请刷新页面

加载更多

Docker安装踩坑:E_FAIL 0x80004005的解决

参考 菜鸟教程--Windows Docker 安装 http://www.runoob.com/docker/windows-docker-install.html 官方文档-Install Docker Toolbox on Windows https://docs.docker.com/toolbox/toolbox_in......

karma123
12分钟前
0
0
js垃圾回收机制和引起内存泄漏的操作

JS的垃圾回收机制了解吗? Js具有自动垃圾回收机制。垃圾收集器会按照固定的时间间隔周期性的执行。 JS中最常见的垃圾回收方式是标记清除。 工作原理:是当变量进入环境时,将这个变量标记为“...

Jack088
昨天
17
0
大数据教程(10.1)倒排索引建立

前面博主介绍了sql中join功能的大数据实现,本节将继续为小伙伴们分享倒排索引的建立。 一、需求 在很多项目中,我们需要对我们的文档建立索引(如:论坛帖子);我们需要记录某个词在各个文...

em_aaron
昨天
27
0
"errcode": 41001, "errmsg": "access_token missing hint: [w.ILza05728877!]"

Postman获取微信小程序码的时候报错, errcode: 41001, errmsg: access_token missing hint 查看小程序开发api指南,原来access_token是直接当作parameter的(写在url之后),scene参数一定要...

两广总督bogang
昨天
31
0
MYSQL索引

索引的作用 索引类似书籍目录,查找数据,先查找目录,定位页码 性能影响 索引能大大减少查询数据时需要扫描的数据量,提高查询速度, 避免排序和使用临时表 将随机I/O变顺序I/O 降低写速度,占用磁...

关元
昨天
15
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部