How eclipse maven project will copy all the jar package to the lib directory?

1. scenario demonstrates

  We know that, maven project jar package which does not exist in the project, the project required jar package are stored in a local warehouse, local warehouse if not, it will download the configuration from a central warehouse, if there is no central repository will give an error;

  As shown above, I think the project will depend on all the jar packages are placed in src / main / webapp / WEB-INF / lib directory, how to achieve?

  The purpose of this is to be hot deployment.

2. Analysis

  By default, in order to get the project dependent jar package, you need to execute maven command to achieve, for example: mvn install

  After the implementation of the project and has already beaten the package will be under the target directory.

3. Solution

   By changing the default package maven directory to achieve.

   The first step: With plug-maven-war-plugin package needed to change the project directory location

<Build> 
    <finalName> mavenProject </ finalName> 
    <plugins> 
        <-! 
            Change the default package directory maven 
            maven default package directory: project / target / project / 
            directory after the change: project / src / main / webapp / 
            change after change: 
            no longer generates the 1.target project directory, which generates only the items corresponding to the war package. 
            2. The project required jar package lib copied to the directory 
        -> 
        <plugin> 
            <the artifactId> Maven-WAR-plugin </ the artifactId> 
            <Configuration> 
                <webappDirectory> $ project.basedir} {/ the src / main / the webapp </ webappDirectory> 
                <warSourceDirectory> $ project.basedir} {/ the src / main / the webapp </ warSourceDirectory>
</build>

  Step two: Change the class files compiled location

  outputDirectory tag to tag body build.

<! - 
    Change the default class file is compiled position maven 
    maven compiler default directory: project / target / classes / 
    directory after the change: Project / src / main / the webapp / the WEB-INF / classes / 
 -> 
<outputDirectory> $ {Project .basedir} / src / main / webapp   / WEB-INF / classes </ outputDirectory>

  As shown in FIG before the change, the change

  Description:

  After the jar by pom.xml update package dependencies, we need to Alt + F5, rebuild the project;

  If you add the pom.xml delete the references or modified version of a jar package, in order to make the lib directory synchronization, you need to manually delete the jar package lib directory under the light of a jar package, otherwise, have been deleted jar packages are not automatically deleted, has been updated version of the package will jar there are several versions.

  Re-use mvn clean install command before you can synchronize the updated package jar to the lib directory.

  The second step is best not to omit, because if you do not modify the default position compiler class, then, there are also cases class files can not be synchronized.

4. Extension 

  When unpacked before the project, which is not mvn install command: expand a

  In eclipse, this does not affect the normal operation of our projects.

  At this point, did not execute mvn install command, nor lib directory jar package. 

  Prerequisite: Select the project - "run as right or debug as

  eclipse automatically pom configuration file copied to the jar package {tomcat / webapps} / project / WEB-INF / lib directory

  Therefore, the project can be properly run without error.

  The reason why the eclipse so smart, because:

  Add this eclipse is set to mavenWeb project

  The project required jar package, is placed under the WEB-INF / lib directory. 

  I do not believe they can test.

  How to add this setting?

  According to the process to create mavenWeb your project, this set is definitely yes, but if not, please click the following:

  First, select the project - "Right Properties -" Deployment Assembly (if you do not have this option, indicating that your project is not a real web project)

  Second, the right side - "Add -" Java Build Path Entries - "Next--" Select Maven Dependencies - "Finish

 

Written in the last

  Which big brother If it is found there is leakage of the carelessness of the article or need to add more content, welcome message! ! !

 related suggestion:

 

Guess you like

Origin www.cnblogs.com/Marydon20170307/p/11863227.html