Maven simple application analysis

When creating a new maven project

1故障:-Dmaven.multiModuleProjectDirectory system property 

is not set. Check $M2_HOME environment variable and mvn 

script match.

 

Go to the location of the jdk version setting in java "edit", behind Default Vm...

Copy and paste: Note that M2_HOME is the name of the maven environment variable, mine is M2_HOME

-Dmaven.multiModuleProjectDirectory=$M2_HOME

 

 

2 Most of the white book errors occur because of the startup memory problem of eclipse

Maven创建 An internal error occurred during

 

Modify the following configuration in the eclipse.ini or myeclipse.ini file:

-Xms512m

-Xmx1024m

Explanation: The first is the smallest initialized memory, the second is the largest occupied memory

 

In the test class if @Test cannot import the jar package

Need to change the version of junit in pom.xml to 4.9

 

3. You can see the dependencies between jar packages in the dependency Hie... in the pom file

4. The address of the Maven central warehouse is as follows. In addition, after entering the page, you usually find the jar package you need, and then the GAV writing will automatically appear. You can directly paste it into the pom file. Some companies use private libraries to download:

    ①. http://www.sonatype.org/nexus/

    ②. http://mvnrepository.com/ (recommended repository)

   ③ http://repo1.maven.org/maven2

 5. Dependency transfer: The jar package may also depend on other jar packages. For example: when using the spring-test jar package, there is also a spring-core package in this jar package, and this package also needs to depend on the commons-logging package. At this point, the project and the commons-logging package are transitive dependencies,

   Shortest path: maven will automatically find the shortest path in the jar package to use

 6引用别的模块的包时,需要把g.a.v粘贴到主动引用的A工程中,前提是被引用工程B需要mvn install了,这样库中才有这个jar包

 7依赖排除:当B工程依赖A工程一部分jar包,则在B的pom中写<exclusion>中间是不需要的A中的jar包GAV</exclusion>

8聚合:成批量的管理子模块,避免每个工程都install一下.

<version>0.0.1-SHAPSHOT</version>

<package>pom</package>

<!--子模块包名-->

<modules>

    <module>../子模块名称</module>

<modules>

 继承:主要是指继承父工程中的jar包,可以简便的管理jar包的版本,抽出了常用的配置

<!-- 1在父工程设置被依赖的jar包的统一版本 -->

<properties>

<spring-mvc.version>4.2.5.RELEASE</spring-mvc.version> 

</properties>

<dependencyManagement>

  <dependencies>

  <dependency>

   <groupId>org.springframework</groupId>

   <artifactId>spring-webmvc</artifactId>

   <version>${spring-mvc.version}</version>

</dependency>

 </dependencies>

</dependencyManagement>

 <!--2子工程的配置(注意查看是否有不需要或者是版本冲突的jar包需要使用<exclusion>标签管理)-->

  <parent>

       <artifactId>partner</artifactId>

    <groupId>父工程名称</groupId>

    <version>0.0.1-SNAPSHOT</version>

    <relativePath>../父工程名称</relativePath>

  </parent>

<!-- 使用父工程中的jar包 -->

  <dependencies>

    <dependency>

   <groupId>org.springframework</groupId>

   <artifactId>spring-webmvc</artifactId>

</dependency>

 </dependencies>

 9如果是普通的web工程创建的时候不能再选择quckstar,而是选择webapp

10 scope意思是范围,

  例:  1<dependency>

    <groupId>junit</groupId>

    <artifactId>junit</artifactId>

    <version>4.9</version>

    <scope>test</scope>

   </dependency>

   说明是junit只在test时参与

  例2 <dependency>

    <groupId>org.springframework</groupId>

    <artifactId>spring-test</artifactId>

    <version>4.2.5.RELEASE</version>

    <scope>compile</scope>

   </dependency>   

spring-test在compile即全程参与

另注依赖范围:

compile:默认是compile,对 编译+测试+运行 都有效

provided:对编译和测试,运行的时候不需要加入

runtime:只在测试和运行时 有效,比较典型的例子 jdbc api,只有在启动代码测试或者运行的时候才会启用

test:只会在测试时有效,比较典型例子 就是junit ,只有再测试的时候 才会启用

11另外注意在web工程中,添加jsp的servlet-api依赖时,需要参考web服务器的容器中是否有自带的servlet-api的jar包,此处可能造成冲突

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326931639&siteId=291194637