Using MAVEN to compile and use the jar package under Lib

Source: Internet
Author: User

In project development, the project is managed by Maven and is a MAVEN project.
In general, jar packages can use Pom.xml to configure management, but there are times when we use an internal jar file in our project, but this file is not open to the MAVEN repository.
We will take the file to our project Web-inf/lib.
If we do not have a special configuration for Pom.xml, MAVEN packaging does not automatically refer to and compile the Lib jar file, so we need to modify the next Pom.xml file.

Modify the configuration of the Maven-compiler-plugin as follows:

<plugin>    <groupId>Org.apache.maven.plugins</groupId>    <artifactid>Maven-compiler-plugin</artifactid>    <version>3.1</version>    <configuration>        <source>1.7</Source>        <target>1.7</target>        <encoding>UTF-8</encoding>        <compilerarguments>            <verbose />            <bootclasspath>${env. Java_home}/jre/lib/rt.jar</bootclasspath>            <extdirs>Src/main/webapp/web-inf/lib</extdirs>        </compilerarguments>    </configuration></plugin>

The other configuration is my original configuration, for LIB reference this problem, only need to add is:
<extdirs>src/main/webapp/WEB-INF/lib</extdirs>

Another popular science, maven directory contract:
The directory where the Pom.xml is located should be the root of the project, assuming the directory is ${proj-dir}, then Maven has the following assumptions:

${proj-dir}/src/main/java--. java files that store the project.

${proj-dir}/src/main/resources--Store project resource files, such as spring, hibernate configuration files.

${proj-dir}/src/test/jave--store all test. java files, such as JUnit test classes.

${proj-dir}/src/test/resources--the test resource file.

${proj-dir}/target--the project output location.

Run a MVN clean Package command, MAVEN will help you clear the target directory, re-build an empty, compile Src/main/java class to target/classes, copy src/main/ Resources files to target/classes, compiling Src/test/java to target/test-classes, copying src/test/resources files to target/test-classes ; then run all the tests; After the test passes, it is packaged with the jar command and stored in the target directory. Maven does a lot of things, but all the users are hidden, it only requires you to follow its convention.

Finish

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Using MAVEN to compile and use the jar package under Lib

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.