文档章节

maven 打包独立可运行jar

Oscarfff
 Oscarfff
发布于 2016/02/13 19:09
字数 629
阅读 134
收藏 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
博文 816
码字总数 97116
作品 0
崇明
后端工程师
私信 提问
加载中

评论(0)

maven打包时加入依赖包及加入本地依赖包

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

王小明123
2014/05/18
6.9W
3
Maven- 使用Maven构建一个可执行jar

How to Create an Executable JAR with Maven 1.最重要的是使用jar类型, 2.利用maven-dependency-plugin来手动创建(方法一) <plugin> </plugin> ①. goal被指定为copy-dependencies,意思......

osc_tek5189e
2018/03/03
6
0
spring-boot-maven-plugin多模块install问题解决办法

一、问题描述:   项目分多个模块,open-eureka注册中心、open-provider服务提供者、open-common公共部分,provider依赖common。父pom使用spring-boot-maver-plugin插件,项目直接运行Mai...

osc_13mpeqmt
2019/04/21
4
0
spring boot 使用assembly插件将依赖jar打包到外部独立文件夹中

spring boot 在打包运行jar的时候,默认会把依赖jar全部打包到一个jar中,这样有一个不方便的地方,就是打包的jar包比较大,每次上传到服务器都要上传好久,这里我们可以使用assembly插件将依...

花树堆雪
2019/12/25
77
0
Java 之 Maven 常用命令

一、Maven 常用命令    在 cmd 中可以通过一系列的 maven 命令对我们的 maven 工程进行编译、测试、运行、打包、安装和部署。   1、compile 命令     compile 是 maven 工程的编译命...

osc_4o5tc4xq
2019/10/11
1
0

没有更多内容

加载失败,请刷新页面

加载更多

IntelliJ 安装 Python 插件

运行 IntelliJ,然后在 IntelliJ 的设置中找到 插件。 然后在插件中搜索 Python 如果你没有安装的话,你应该是没有办法找到的。 你可以选择搜索 MarketPlace 选择官方的插件进行安装就可以了...

honeymoose
14分钟前
4
0
记一次element ui table 数据改变UI没渲染的坑

我要根据外界的值来判断我显示的table是单选还是多选,但是props的值变了UI却一直没什么反应,后来采用了强制刷新,在组件上加了一个:key= XXX,这个key根据外界的值得变化而变化,问题解决...

osc_5p8bxoq2
15分钟前
12
0
ASP.NET Core MVC如何上传文件及处理大文件上传

用文件模型绑定接口:IFormFile (小文件上传) 当你使用IFormFile接口来上传文件的时候,一定要注意,IFormFile会将一个Http请求中的所有文件都读取到服务器内存后,才会触发ASP.NET Core MV...

osc_yq7pxbpa
16分钟前
12
0
ASP.NET Core MVC如何上传文件及处理大文件上传

用文件模型绑定接口:IFormFile (小文件上传) 当你使用IFormFile接口来上传文件的时候,一定要注意,IFormFile会将一个Http请求中的所有文件都读取到服务器内存后,才会触发ASP.NET Core MV...

osc_dihgscoq
17分钟前
15
0
马斯克的宇宙飞船爆炸了!但不会影响SpaceX的载人发射

  该炸的 Starship 原型机总是会炸的,该进行的载人任务也总是会发射的。   承载着 SpaceX 未来星际旅行梦想的 Starship 宇宙飞船原型机再一次在测试中以全部炸毁收场。      但需要...

osc_35ne77sz
19分钟前
7
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部