How Maven introduces (or references/uses) a custom (or local/third-party) jar in three Ways graphics tutorial method Two The simplest

Source: Internet
Author: User
Tags cas

Ext: 52798194

Preparatory work:

If I have a custom jar that is: 123456.jar,http://download.csdn.net/detail/wabiaozia/9870838

If you do not want to download, you can follow the https://jingyan.baidu.com/article/046a7b3ed8b23ef9c27fa9b9.html operation to get the jar.

The source code in the jar package is:

    1. public class Regexutils {
    2. /**
    3. * Verify Email
    4. * @param email address, format: [email protected],[email protected],xxx Representative email service provider
    5. * @return Verify Success returns TRUE, validation failure returns false
    6. */
    7. public static Boolean checkemail (String email) {
    8. String regex = "\\[email protected]\\w+\\. [A-z]+ (\\.[ a-z]+)? ";
    9. Return pattern.matches (regex, email); }
    10. }

Usage Recommendations:

The second way to introduce a local jar is recommended

Introduce a custom Jar method one:

1 First find your MAVEN profile {Your Maven path}\conf\settings.xml, then open settings.xml to see the root directory where you store the local jar path. For example, my Maven root directory is C:\Users\user\.m2\localRepository. The jar I define myself as long as it is placed in the root directory according to certain rules, the following will be described in detail.

2 If your custom jar package is 123456.jar, you want to introduce your jar package in the Pom.xml of your project

    1. <dependency>
    2. <groupid>123456</groupid>
    3. <artifactid>123456</artifactid>
    4. <version>1.0</version>
    5. </dependency>


3 Create the following folder under your root directory folder

Create a 123456 folder in the root directory C:\Users\user\.m2\localRepository\ > Create a 123456 folder-----> re-create the 1.0 folder

Finally put 123456.jar into the 1.0 folder

Reprint please indicate link: http://blog.csdn.net/wabiaozia?viewmode=contents

As shown

4 Change 123456.jar to 123456-1.0.jar and create file 123456-1.0.pom. Note here that the file suffix created is the dot pom instead of the dot xml (". Pom" is not ". Xml").

Then write the following in the 123456-1.0.pom

    1. <project>
    2. <modelversion>1.0.0</modelversion>
    3. <groupid>123456</groupid>
    4. <artifactid>123456</artifactid>
    5. <version>1.0</version>
    6. </project>

5 introduced in the Pom.xml dependency of your project.

    1. <dependency>
    2. <groupid>123456</groupid>
    3. <artifactid>123456</artifactid>
    4. <version>1.0</version>
    5. </dependency>


6 If you pom.xml an error


Then tick the force update of snapshots/releases option.

7 use in Project code:

boolean b = RegexUtils.checkEmail(email);

8 about Groupid,artifactid How to write one more example

The location of the jar package

Introduced in Pom.xml

    1. <dependency>
    2. <Groupid>com.taibao</groupid>
    3. <artifactid>butils</artifactid>
    4. <version>1.0</version>
    5. </dependency>

Introduce a custom Jar method two:

Reference http://blog.csdn.net/tech4j/article/details/45372263

Make sure that the MVN command (which can be verified by mvn-v) is used correctly in cmd, and then use the following command:

MVN Install:install-file-dfile=d:\ojdbc7.jar-dgroupid=com.tech4j.driver-dartifactid=oracle-connector-java- Dversion=12.1-dpackaging=jar

In this command, the-dfile parameter refers to the path where you customized the jar package file, and in turn specifies the custom GroupID, Artifactid, and version information.

In this way, you can easily and quickly install third-party jar packages to the local repository for use by MAVEN projects. For example:

<Dependency>       <groupId>Com.tech4j.driver</groupId>        <Artifactid>Oracle-connector-java</Artifactid>        <version>12.1</version> </Dependency>

Introduce the custom Jar method three:

  1. <dependency>
  2. <groupid>org.jasig.cas</groupid>
  3. <artifactid>cas-server-webapp</artifactid>
  4. <version>4.2.3</version>
  5. <type>war</type>
  6. <!--Note that the scope is System --
  7. <scope>system</scope>
  8. <!--<systemPath>C:/Users/ice-wee/Downloads/cas-server-webapp-4.0.3.war</systemPath>--
  9. <Systempath>${project.basedir}/suiyijiandewenjianjia/cas-server-webapp-4.0.3.war</ systempath>
  10. <!--Systempath can write 1 Local path can also write 2 project root path, project root path is not relative classpath. -
  11. </dependency>

3.1 maven built-in variable description:
${BASEDIR} Project root directory
${project.build.directory} build directory, default to target
${project.build.outputdirectory} build process output directory, default to Target/classes
${project.build.finalname} output name, default is ${project.artifactid}-${project.version}
${project.packaging} package type, default to Jar
${PROJECT.XXX} contents of any node of the current Pom file

3.2 Examples of Use

Project Root path See figure: my Blog all articles link: http://blog.csdn.net/wabiaozia?viewmode=contents

Create a folder under Project WebApp: Suiyijiandewenjianjia, copy the Cas-server-webapp-4.0.3.war to this folder

Summarize:

The third way to use Systempath packaging is not to put the jar into the war, if you want to hit the war can be used in my article mentioned in the first two ways. We typically lack a jar or a few jars in our project, and the introduction of a local jar is the second way I refer to it in terms of simplicity and speed efficiency. You can use bulk import if there are many jars missing, but it is not recommended because there are a lot of jars that you should first consider, why not put the environment well, and not allow the project to lack so many jars.

Finally: How to bring the local jar into the war package

Http://www.cnblogs.com/hzm112567/p/6531654.html

My blog All articles link: http://blog.csdn.net/wabiaozia?viewmode=contents

(go) how Maven introduces (or references/uses) a custom (or local/third-party) jar in three ways graphic tutorial method two The simplest

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.