Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Use maven to package swing projects into executable jar packages (including dependencies)

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the method of breaking a project into an executable jar package through maven.

This article requires readers to have basic knowledge of maven, understand the general configuration of maven, plug-in configuration, understand the concept of maven phase, goal, and understand the role of dependency and manifest.

Prerequisites:

(the method described in this paper is applicable to the characteristics of the project)

1. The project must be a maven project

3. There must be a main entry class in the project, which can be executed when the user double-clicks the packaged jar file.

Package:

The first case: stand-alone projects with no third-party dependency packages

In this case, we need maven's maven-jar-plugin plug-in to help us pack. Please add the following to the plugin configuration in the project pom.xml: (see the comments section)

... Maven-jar-plugin 2.3.2 true lib/ com.yourProjectPackage.YourEntranceClass...

Then use mvn clean install to compile and install your project. At the end of the command execution, a jar file and a lib folder are generated (if your project references 3rd-party dependencies). Double-click the jar file and you will see the effect immediately. Projects with interfaces should be able to see the main interface (if your program is right), without interfaces, you should be able to see relevant information from your machine's java console, or the project itself has log output or magical effects, you can directly view the output results.

The second case: project + third-party dependency package

In this case, you cannot use the maven-jar-plugin plug-in to package. We are going to use another plugin, maven-assembly-plugin. This plug-in can help us package our projects flexibly (not only for jar projects, but also for ear, war and other projects. This article only describes how to package executable jar packages). Here, we use this plug-in to combine our source code compilation results with the project's dependencies to form a jar file.

Here is the configuration part of the plugin in the pom.xml of the project:

Maven-assembly-plugin 2.6 com.your.package.YourEntranceClass jar-with-dependencies make-assembly package single

After adding this plugin, you can clean install your maven project. Then you will find something like this in the console after the execution of the maven command:

-maven-install-plugin:2.4:install (default-install) @ MvnCfgSwitcher-

Installing F:\ uuuu\ vvvv\ Wwwww\ target\ Wwwww-1.0-SNAPSHOT.jar to Y:\ mvn_repo\ com\ yourname\ Wwwww\ 1.0-SNAPSHOT\ Wwwww-1.0-SNAPSHOT.jar

Installing F:\ uuuu\ vvvv\ Wwwww\ pom.xml to Y:\ mvn_repo\ com\ yourname\ Wwwww\ 1.0-SNAPSHOT\ Wwwww-1.0-SNAPSHOT.pom

Installing F:\ uuuu\ vvvv\ Wwwww\ target\ Wwwww-1.0-SNAPSHOT-jar-with-dependencies.jar to Y:\ mvn_repo\ com\ yourname\ Wwwww\ 1.0-SNAPSHOT\ Wwwww-1.0-SNAPSHOT-jar-with-dependencies.jar

The blue identification part is the executable jar file of the generated all-in-one.

Double-click the package result and try it, dear!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report