How to use maven to package the dubbo project into a jar package to run
The method discussed in this article to use maven to package the dubbo project into a jar package for running is: use the maven packaging plug-in maven-jar-plugin to add some code at the end of the pom.xml file. Interested friends can take a look, I hope it can help you
maven packaging method
Use maven packaging plug-inmaven-jar-plugin
at Add the following code at the end of the pom.xml
file. maven-dependency-plugin
refers to copying the dependent jar package to the specified directorymaven-resources-plugin
Copying the dependent resources to the specified directory
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.6</version> <configuration> <archive> <manifest> <!-- 是否依赖外部jar包 --> <addClasspath>true</addClasspath> <!-- 依赖外部jar包路径 --> <classpathPrefix>lib/</classpathPrefix> <!-- 启动函数 --> <mainClass>com.alibaba.dubbo.container.Main</mainClass> </manifest> </archive> <!-- 打包之后输出目录 --> <outputDirectory>${project.build.directory}/maven-archiver</outputDirectory> <!-- 剔除已打包的配置文件 --> <excludes> <exclude>*.*</exclude> <exclude>config/*</exclude> <exclude>config/tencent/*</exclude> <exclude>META-INF/spring/*</exclude> </excludes> </configuration> </plugin> <!-- 拷贝依赖的jar包到lib目录 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.8</version> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory> ${project.build.directory}/maven-archiver/lib </outputDirectory> </configuration> </execution> </executions> </plugin> <!-- 拷贝依赖的资源文件包到resources目录 --> <plugin> <artifactId>maven-resources-plugin</artifactId> <executions> <execution> <id>copy-resources</id> <phase>package</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/maven-archiver/resources</outputDirectory> <resources> <resource> <directory>${basedir}/src/main/resources</directory> <filtering>true</filtering> </resource> </resources> </configuration> </execution> </executions> </plugin> </plugins> </build>
- How to run the jar package
The directory structure after packaging
Contains the class file and the required configuration file information (excluding excludes configuration files)
Contains the information required for operation in MANIFEST.MF
Class-Path: lib/commons-beanutils-1.8.3.jar lib/commons-betwixt-0.8.jar ... Main-Class: com.alibaba.dubbo.container.Main
java -jar
Start command
java -jar When executing the command, the Main-Class parameter in the directory META-INFMANIFEST.MF will be used. This is the entry point of the function specified during packaging.
java -jar x-0.0.1-SNAPSHOT.jar
java -cp
Startup command
java -cp .:x-0.0.1-SNAPSHOT.jar packname.mainclassname
Because I need to reference external resources files in my project, I usually start in this way
The configuration file address is an absolute path
java -cp /Users/username/resources:dubbo-service-1.0.jar com.alibaba.dubbo.container.Main
-cp
and -classpath
have the same effect
java -cp is the dependency of the specified operation The path of other classes, usually class libraries, jar packages, etc. Multiple dependencies are separated by semicolons ";" on Window
and ":" on linux
.
Expressions support wildcards
java -cp .:/Users/username/*.jar packname.mainclassname
- Type into a jar package
If you need to run all dependent jar packages into one jar package, you can use maven-shade-plugin
This plugin.
The main function of this plug-in is to package the dependent jar package into the current jar package, and rename the class during packaging, which can solve the multi-version conflict of the jar package. For details, you can check the official plug-in documentation.
Related tutorials: Java video tutorial
The above is the detailed content of How to use maven to package the dubbo project into a jar package to run. For more information, please follow other related articles on the PHP Chinese website!

Start Spring using IntelliJIDEAUltimate version...

When using MyBatis-Plus or other ORM frameworks for database operations, it is often necessary to construct query conditions based on the attribute name of the entity class. If you manually every time...

Java...

How does the Redis caching solution realize the requirements of product ranking list? During the development process, we often need to deal with the requirements of rankings, such as displaying a...

Conversion of Java Objects and Arrays: In-depth discussion of the risks and correct methods of cast type conversion Many Java beginners will encounter the conversion of an object into an array...

Solutions to convert names to numbers to implement sorting In many application scenarios, users may need to sort in groups, especially in one...

Detailed explanation of the design of SKU and SPU tables on e-commerce platforms This article will discuss the database design issues of SKU and SPU in e-commerce platforms, especially how to deal with user-defined sales...

How to set the SpringBoot project default run configuration list in Idea using IntelliJ...


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.