java web pom.xml

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java web pom.xml相关的知识,希望对你有一定的参考价值。

java web 开发,maven项目,pom.xml配置中,有<parent>和<dependencies>两个节点,它们的本质区别是什么(在我理解两者都是去仓库下载东西到本地仓库,不是很清楚本质区别到底是什么)
有哪位大神知道的,给小弟讲解下,不胜感激!

如果这个java web项目的pom文件中,同时有parent和dependencies两个节点,那么在你打war包时,parent里的dependencies依赖也会被引入到web项目中。这只是个配置方式的问题。项目自己的pom里的dependencies只会在项目内部使用,那些被抽成parent的pom一般都是公用dependency或者其它配置,既可以给你的web项目用,又可以给其它任何maven项目用。 参考技术A parent是上级pom.xml

dependencies是依赖的项目(.jar),同级的追问

感谢您的回答,请问parent是指本项目只继承父项目的dependencies吗?

Java Web 常用Maven 依赖

Java Web 常用Maven 依赖

1. 基本pom.xml结构

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.marving</groupId>
    <artifactId>sshDemo</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>SpringMVC_Spring_Hibernate</name>
    <url>http://maven.apache.org</url>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>$java.version</source>
                    <target>$java.version</target>
                    <encoding>$project.build.sourceEncoding</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

2. 配置properties

<properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <java.version>1.8</java.version>
  <!-- spring版本号 -->  
  <spring.version>4.2.5.RELEASE</spring.version>
  <!-- hibernate版本号 -->  
  <hibernate.version>4.2.2.Final</hibernate.version>
  <!-- mybatis版本号 -->  
  <mybatis.version>3.2.6</mybatis.version> 
</properties>

3. Spring 相关

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-core</artifactId>
  <version>$spring.version</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-context</artifactId>
  <version>$spring.version</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-beans</artifactId>
  <version>$spring.version</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-jdbc</artifactId>
  <version>$spring.version</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-orm</artifactId>
  <version>$spring.version</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-tx</artifactId>
  <version>$spring.version</version>
</dependency>
<!-- 包含ContextLoaderListener 监听器 -->
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-web</artifactId>
  <version>$spring.version</version>
</dependency>

4. Spring MVC相关

<!-- 使用SpringMVC需配置 -->
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-webmvc</artifactId>
  <version>$spring.version</version>
</dependency>
<!--Spring MVC 返回json-->  
<dependency>  
  <groupId>com.fasterxml.jackson.core</groupId>  
  <artifactId>jackson-core</artifactId>  
  <version>2.5.2</version>  
</dependency>  

<dependency>  
  <groupId>com.fasterxml.jackson.core</groupId>  
  <artifactId>jackson-databind</artifactId>  
  <version>2.5.2</version>  
</dependency>

5. 持久层相关

hibernate

<!-- hibernate -->
<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-core</artifactId>
  <version>$hibernate.version</version>
</dependency>

mybatis

<!-- mybatis核心包 -->  
<dependency>  
  <groupId>org.mybatis</groupId>  
  <artifactId>mybatis</artifactId>  
  <version>$mybatis.version</version>  
</dependency>  
<!-- mybatis/spring包 -->  
<dependency>  
  <groupId>org.mybatis</groupId>  
  <artifactId>mybatis-spring</artifactId>  
  <version>1.2.2</version>  
 </dependency>

6. log4j & slf4j

<dependency>
  <groupId>log4j</groupId>
  <artifactId>log4j</artifactId>
  <version>1.2.16</version>
</dependency>
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-api</artifactId>
  <version>1.6.1</version>
</dependency>
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-nop</artifactId>
  <version>1.6.4</version>
</dependency>

7. 数据源

c3p0

<!-- c3p0数据源 -->
<dependency>
  <groupId>c3p0</groupId>
  <artifactId>c3p0</artifactId>
  <version>0.9.1.2</version>
</dependency>

Druid

<!-- Druid 数据源 -->
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid</artifactId>
    <version>1.0.29</version>
</dependency>

9. json 处理

<!--json-lib-->    
<dependency>    
  <groupId>net.sf.json-lib</groupId>    
  <artifactId>json-lib</artifactId>    
  <version>2.4</version>    
  <classifier>jdk15</classifier>    
</dependency>  
<dependency>
  <groupId>com.alibaba</groupId>
  <artifactId>fastjson</artifactId>
  <version>1.2.24</version>
</dependency>

10. 其他

<dependency>
  <groupId>commons-dbcp</groupId>
  <artifactId>commons-dbcp</artifactId>
  <version>1.4</version>
</dependency>

<!-- mysql连接 -->
<dependency>
  <groupId>mysql</groupId>
  <artifactId>mysql-connector-java</artifactId>
  <version>5.1.34</version>
</dependency>

<dependency>
  <groupId>org.apache.commons</groupId>
  <artifactId>commons-lang3</artifactId>
  <version>3.3.2</version>
</dependency>

如要产生为每个类生成javadoc,将下面的plugin加入内。

<!-- generate java doc -->
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-javadoc-plugin</artifactId>
  <version>2.9.1</version>
  <configuration>
    <javadocDirectory>target/javadoc</javadocDirectory>
    <reportOutputDirectory>target/javadoc</reportOutputDirectory>
    <charset>UTF-8</charset>
    <encoding>UTF-8</encoding>
    <docencoding>UTF-8</docencoding>
    <show>private</show>
  </configuration>
</plugin>

转自 https://blog.csdn.net/Mercop/article/details/71244609?spm=1001.2014.3001.5501

以上是关于java web pom.xml的主要内容,如果未能解决你的问题,请参考以下文章

Java web 中如何测试Java类

java Java Web获取Web应用根路径

java的web编程是啥意思?

java web项目中,模块的命名规则是啥?

如何实现java实现web服务器之间转换?

java Web项目创建之一(普通java web项目的创建与发布)