Make a maven project and a third-party dependency into a common jar without a main class

The recently developed project needs to write an SDK for a jdk1.7 project, and this jdk1.7 project is not a maven project, but a kind of original java web. In that case, the idea is there. When developing this SDK, I definitely want to use Maven. When packaging, it can be made into a common jar package, and the third-party dependencies can also be made into the jar package. It should also be noted that the development and compilation should use jdk1.7, so that this jar package can be directly provided to them without JDK version problems. With a clear idea, we began to develop a demo.

There are many scenarios in which a maven project and a third-party dependency are made into ordinary jars without main class. For example, many people like to package HttpClient by themselves, but they can't develop a new service. Just re package it or copy and paste it. For another example, I have written several tool classes, which are common. For example, these can be typed as ordinary jars without main class. The next time you develop a new service, you can directly reference them.

Let's take a look at the demo:

This is the directory of the demo. It's a simple ApplicationUtil. Take a look at this:


A test method returns a string.

You can see pom XML, a maven project, this pom XML is the key. Take a look:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=""

    <description>PDM STAIR</description>



            <!--Specify the compilation level of the project-->
                    <!-- Encoding format -->

            <!--Enter dependencies together jar Package, i.e. heavyweight jar-->


You can see that jdk uses 1.7 and introduces many third-party dependencies. Finally, Maven assembly plugin is used to add the third-party dependencies into the jar package.

This is all right. Then, package it with maven's package. Take a look at the results after packaging:

You can see that there are two jars. The above one is a lightweight jar without third-party dependencies. The following one with jar with dependencies is a heavyweight jar that contains third-party dependencies. You can decompile this heavyweight jar:

You can see that the project you wrote and the external references are all tied together. Although it is a little messy, the goal has been achieved. The

You can test whether this heavyweight jar can be directly referenced by a non maven project:

This is an original java web project. The jar package is directly referenced. You can see that it is ok.

Tags: Maven

Posted by matty84 on Tue, 31 May 2022 23:44:00 +0530