Maven warehouse Understanding, how to introduce local packages, maven multiple ways to hit the executable jar package

Source: Internet
Author: User
Tags join log4j

Understanding of the Maven warehouse see: http://blog.csdn.net/wanghantong/article/details/36427433

the role of scope in the Maven dependency relationship Java code Dependency Scope also introduces <scope> in the,<dependency> of Pom 4, which primarily manages dependent deployments. Currently, the scope of a dependency <scope> can use 5 values: When defining a project's dependencies, we can specify the scope of the dependency by scope.   Scope values are compile, runtime, test, provided, system, and import. Compile: This is the default scope for dependencies, which means that compile is used by default when no scope is specified for a dependency.   Dependencies in the compile range are valid in all cases, including run, test, and compile time. Runtime: Indicates that the dependency is required only at run time and is not required at compile time.   This type of dependency will be accessible under the classpath of Run and test.   Test: Indicates that the dependency is only useful for testing, including the compilation and operation of the test code, and has no effect on normal project operation.   Provided: Indicates that the dependency will be provided by the JDK or run container at runtime, which means that the dependency provided by Maven is only used when compiling and testing, and will be provided by the JDK or runtime container at runtime. System: When scope is system, it means that the dependency is provided by us and does not need maven to go to the warehouse to find it. Specifying scope as system needs to be used with another property element, Systempath, which represents the location of the dependency on the current system, using an absolute path.

The Java code Pom file can reference some built-in properties (Maven predefined can be used directly) ${basedir} project root directory ${version} for project versions;   ${project.basedir} with ${basedir};   ${project.version} indicates the project version, same as ${version};   ${project.build.directory} build directory, default to target ${project.build.sourceencoding} to indicate the main source code format;   ${project.build.sourcedirectory} represents the main source path;   ${project.build.finalname} indicates the output file name; ${project.build.outputdirectory} build process output directory, default to Target/classes

How do I introduce a local package to a MAVEN project?

For example, I'm hitting a jar package from another project and introducing it into an existing project.

method One: Place the package to be introduced in the directory, such as the Lib directory, modify the Pom file, join the dependency and scope to be set to system

Java code <dependencies> <dependency> <groupId>com.fbcds</groupId> <ar Tifactid>fbcds</artifactid> <version>1.0</version> <scope>system</scope&           Gt <systemPath>${project.basedir}/lib/fbcds.jar</systemPath> </dependency> </dependencies>



After the above setup is complete, run the MVN Package command to execute successfully. But the package that is called out does not contain the Lib directory and Fbcds.jar the referenced package, that is, the package is not an executable jar. So personal development words can be used in this way if team development please use method two.

method Two: Install the jar package to be introduced into the local repository

1, first put the jar package to be introduced in a directory, you need to change the package name, such as Fbcds.jar modified to Fbcds-1.0.jar, such as F:\lib directory, in the command line CD to the Lib directory, execute the following command: Java code MVN install: Install-file-dfile=fbcds-1.0.jar-dgroupid=fbcds-dartifactid=fbcds-dversion=1.0-dpackaging=jar mvn Install: Install-file-dfile=ojdbc7-1.0.jar-dgroupid=ojdbc7-dartifactid=ojdbc7-dversion=1.0-dpackaging=jar

2, modify the project Pom file to join the package corresponding to the dependency

  Java code    <dependencies>       <dependency>         <groupId>log4j</groupId>          <artifactId>log4j</artifactId>         < version>1.2.17</version>       </dependency>        <dependency>         <groupid>fbcds</ groupid>         <artifactId>fbcds</artifactId>          <version>1.0</version>        </dependency>       <dependency>           <groupId>ojdbc7</groupId>          <artifactid>ojdbc7</artifactId>         <version>1.0</version >        </dependency>     </dependencies>   

The above Fbcds and OJDBC7 are the dependencies of the newly added reference package.

When you are finished, you can see the corresponding folder contents in the Local warehouse:



how maven hits the executable jar package

Prerequisite: The jar package to be introduced to the local repository has been successfully installed

method One, using the Maven-shade-plugin plugin to hit the executable jar package

Plugin Lookup Link: http://maven.apache.org/plugins/

1. Test Class Code

  Java code    package com.lwf.test;      import java.sql.connection;    import java.sql.drivermanager;   import java.sql.resultset;   Import  java.sql.SQLException;   import java.sql.statement;      import  com.eclink.fbcis.store.storedao;      public class testclass {       public static void main (String[] args)  {            storedao a = new storedao ();     &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SYSTEM.OUT.PRINTLN ("------"  + a.tostring ());           Connection con = null;            Statement st = null;            resultset rs = null;           try  {               string sql  =  "select * from temp_head where temp_no= ' c530015i19008015 '";               class.forname (" Oracle.jdbc.driver.OracleDriver ");                con = drivermanager.getconnection ("Jdbc:oracle:thin:@//10.101.2.19:1521/pdbqmytcis", " Qmytcis "," qmytcis123 ");               st

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.