文档章节

maven 打包独立可运行jar

Oscarfff
 Oscarfff
发布于 2016/02/13 19:09
字数 629
阅读 98
收藏 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

没有更多内容

加载失败,请刷新页面

加载更多

macOs-挂载能读写的NTFS硬盘

转自:https://nicklinyi.gitee.io/blog/2018/04/macOS-ntfs.html Mac本身是支持NTFS写入的,只是NTFS是微软开发,由于版权和技术细节原因,苹果不愿公开说自己支持NTFS写入,也是有自己以后...

北风刮的不认真了
24分钟前
2
0
Namespace 命名空间

命名空间可以定义为一种封装方式。 为了解决开发中库和程序中可重用类和方法问题: 1.解决 PHP内部方法类/方法/常量 或者第三方 类/方法/常量之间的命名冲突 2.能够简化为了防止命名冲突而给...

忙碌的小蜜蜂
27分钟前
1
0
CDH的坑之Deploy Client Configuration Failed

Deploy Client Configuration Failed 1.问题描述 当使用CDH增添spark服务的时候,出现了以下错误: Faile to deploy client configuration to the cluster. 具体如下图: 2.思路 网上查了...

星汉
28分钟前
2
0
java guava 集合的操作:交集、差集、并集

Guava:google的工程师利用传说中的“20%时间”开发的集合库,它是对jdk提供的扩展,提供了很多实用的类来简化代码。 开源地址:https://github.com/google/guava jar包下载:http://maven....

帅的不像男的
29分钟前
2
0
从八个层面比较分析 Java 8, RxJava, Reactor

响应式编程在单机环境下是否鸡肋? 结论是:没有结论,我觉得只能抱着怀疑的眼光审视这个问题了。另外还聊到了 RSocket 这个最近在 SpringOne 大会上比较火爆的响应式”新“网络协议,githu...

小刀爱编程
31分钟前
2
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部