[Maven] Maven usage records

1, add the jar package to the local maven repository

command:

 mvn install:install-file -DgroupId=com.baidu -DartifactId=ueditor -Dversion=1.0.0 -Dpackaging=jar -Dfile=ueditor-1.1.2.jar 

2, packaged together will depend

If you do not display configuration, dependence is ignored, just pack the code belong to this project compiled into .class files.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.baidu.ra</groupId>
    <artifactId>LoadTester</artifactId>
    <version>1.0</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <jmeter-version>3.0</jmeter-version>
    </properties>
    <dependencies>

        <dependency>
            <groupId>org.apache.jmeter</groupId>
            <artifactId>ApacheJMeter_core</artifactId>
            <version>${jmeter-version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.jmeter</groupId>
            <artifactId>ApacheJMeter_java</artifactId>
            <version>${jmeter-version}</version>
            <scope>provided</scope>
        </dependency>

        < Dependency > 
            < groupId > com.baidu.rr </ groupId > 
            < artifactId > RA </ artifactId > 
            < Version > 1.0 </ Version > 
            <-! Here can not be configured wrong, formerly provided, can not find the cause runtime related classes. Note specific reasons between the back -> 
            < scope > the compile </ scope > 
        </ dependency > 

    </ Dependencies > 

    < Build > 
        < a finalName > $ {Project.finalName>
        <defaultGoal>install</defaultGoal>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-jar-plugin</the artifactId > 
                < Configuration > 
                    < Archive > 
                        < the manifest > 
                            <-! inform maven-jar-plugin to add a Class-Path element to the MANIFEST.MF file, and include all the dependencies in the Class-Path element -> 
                            < addClassPath > to true </ addClassPath > 
                            <-! all dependencies lib folder should be located   -> 
                            < classpathPrefix > lib / </ classpathPrefix > 
                            <-!   when the user performs the command lib JAR files using the element defined to be executed the class name   -> 
                            < mainClass > com.baidu.LoadTester </mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        < Goals > 
                            < Goal > Copy-Dependencies </ Goal > 
                        </ Goals > 
                        < Configuration > 
                            <-! $ {} Project.build.directory Maven is built-in variable, default target -> 
                            < the outputDirectory > $ {Project } .build.directory / lib </ the outputDirectory > 
                            <-! indicating whether or not a packet containing depend indirectly   -> 
                            < excludeTransitive > to false </ excludeTransitive > 
                            <-! indicates a copy jar file version information removed -> 
                            < stripVersion >true</ StripVersion > 
                        </ the Configuration > 
                    </ Execution > 
                </ Executions > 
            </ plugin > 
       <-! Here can not add, without words the target folder, there will be a lib folder, publish the entire program time, lib folders and files need to be copied over LoadTester.jar together. This scenario is used: individually placed will depend ->
            <! - If we add here, the lib folder will be packed to go inside LoadTester.jar ->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
                <executions>
                    <execution>
                        <id>assemble-all</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

 

 

Remarks:

(1) compile (compile range)
the compile is the default range; if not provided a range, that range is dependent on the scope of the compilation. Compiling range depends on all available in the classpath, while they will be packaged.
(2) provided (provided range)
Provided rely only when used after a container has been provided or JDK this dependency. For example, if you develop a web application, you may need to compile available in the classpath Servlet API to compile a servlet, but you do not want to include the Servlet API in the packaged WAR; the Servlet API JAR of your application server or servlet container available. It has provided a range of dependence can be used in compiling classpath (not runtime). They are not transitive, it will not be packaged.
(3) runtime (running range)
Runtime At runtime dependency and test systems need, but need not at compile time. For example, you may only need JDBC API JAR at compile time, but only when it needs to run the JDBC
driver implementation.
(4) test (test range)
the Test range depends in general compile and run time are not needed, they can be used only in test compilation and test operation phase.
(5) system (system-wide)
System range depends similar provided, but you must explicitly provide a path for the local system JAR file. This is done to allow the compiler based on local objects, and these objects are part of the system library. This component should be always available, Maven will not go looking for it in the warehouse. If you depend on a range set to system-wide, you must provide a systemPath element. Note that this range is not recommended (you should always try to rely on references from public or custom Maven repository).

 

Guess you like

Origin www.cnblogs.com/tigerhsu/p/11047435.html