MAVEN package contains local jar

Source: Internet
Author: User

The project requires the use of MAVEN's packaging tools to generate a zip archive, using a plugin that is assembly-plugin. For some special reasons, it is necessary to use some local jar to rely on, and after loading the external jar there is no problem in the encoding process, but it has been reported that "package does not exist".

Think about it: MAVEN is essentially a plug-in framework, and its core does not perform any specific build tasks, so while the project is normally dependent on the development process without any problems, the local jar must not be found when it is packaged.

There are many solutions to this problem, such as joining a local warehouse, setting up a Maven, and so on, if you need these solutions, Google Baidu, a lot of information.

Because the MAVEN compiler uses the plug-in is Maven-compiler-plugin, so can only find the problem on the maven-compiler-plugin, the normal maven-compiler-plugin simple configuration is as follows:

<plugin>    <groupId>Org.apache.maven.plugins</groupId>    <Artifactid>Maven-compiler-plugin</Artifactid>    <Configuration>        <Source>1.8</Source>        <Target>1.8</Target>        <encoding>UTF-8</encoding>    </Configuration></plugin>

If you need to rely on the local jar when packaging, you need to modify the configuration to add the following:

<plugin>    <groupId>Org.apache.maven.plugins</groupId>    <Artifactid>Maven-compiler-plugin</Artifactid>    <Configuration>        <Source>1.8</Source>        <Target>1.8</Target>        <encoding>UTF-8</encoding>        <compilerArguments> <extdirs>${project.basedir}/src/lib</extdirs> </compilerarg Uments>    </Configuration></plugin>

If you are using a MAVEN version higher than 3.1, the above configuration has been deprecated and needs to be modified as follows:

<plugin>    <groupId>Org.apache.maven.plugins</groupId>    <Artifactid>Maven-compiler-plugin</Artifactid>    <Configuration>        <Source>1.8</Source>        <Target>1.8</Target>        <encoding>UTF-8</encoding>        <compilerArgs> <arg>-extdirs</arg> <arg>${project.basedir}/src/lib< /arg> </compilerArgs>    </Configuration></plugin>

Note that it is best to add ${project.basedir} for better compatibility.

Modified the above compiled plug-in, packaging normal, no longer an error, but there is a new problem arises. The generated zip package does not contain a dependent local jar.

Modify the configuration file of the Maven-assembly-plugin plugin to add the following configuration:

< Fileset >          < Directory >src\lib</directory>    <OutputDirectory  >lib</outputdirectory></fileset  >

It means to output the jar under the src\lib to the target root lib.

At this point, using the MAVEN Package command, it has been able to run properly and successfully put the local jar packet into the zip archive directory.

MAVEN package contains local jar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.