当前位置:首页 > 服务端 > 结合实际项目分析pom.xml

结合实际项目分析pom.xml

 1 <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">
 2   <modelVersion>4.0.0</modelVersion>
 3   <groupId>com.wang</groupId>
 4   <artifactId>test-maven-server-console</artifactId>
 5   <version>0.0.1-SNAPSHOT</version>
 6   <name>test-maven-server-console</name>
 7   <packaging>war</packaging> 
 8   <properties>
 9       <warPackageName>MyWebAppDemo</warPackageName>
10         <tomcat.server>tomcat</tomcat.server>
11         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12   </properties>
13   
14   <dependencies>
15   <!-- 
16       <dependency>
17           <groupId>com.wang</groupId>
18           <artifactId>test-maven-api</artifactId>
19           <version>0.0.1-SNAPSHOT</version>
20       </dependency>
21    -->
22    
23    <dependency>
24         <groupId>org.springframework</groupId>
25         <artifactId>spring-context</artifactId>
26         <version>4.2.6.RELEASE</version>
27     </dependency>
28       <dependency>
29         <groupId>org.springframework</groupId>
30         <artifactId>spring-web</artifactId>
31         <version>4.2.6.RELEASE</version>
32     </dependency>
33 
34     <dependency>
35         <groupId>com.alibaba</groupId>
36         <artifactId>dubbo</artifactId>
37         <version>2.5.3</version>
38         <exclusions>             
39           <exclusion>                
40           <groupId>org.springframework</groupId>                
41           <artifactId>spring</artifactId>             
42           </exclusion>         
43           </exclusions>    
44     </dependency>
45       
46       <dependency>
47           <groupId>org.apache.zookeeper</groupId>
48           <artifactId>zookeeper</artifactId>
49           <version>3.4.6</version>
50       </dependency>
51   
52       <dependency>
53           <groupId>com.github.sgroschupf</groupId>
54           <artifactId>zkclient</artifactId>
55           <version>0.1</version>
56       </dependency>
57   </dependencies>
58   
59   <build>
60       <finalName>${warPackageName}</finalName>
61       <plugins>
62           <plugin>
63             <groupId>org.apache.maven.plugins</groupId>
64             <artifactId>maven-compiler-plugin</artifactId>
65             <version>3.1</version>
66             <configuration>
67               <source>1.8</source>
68               <target>1.8</target>
69             </configuration>
70         </plugin>
71         <plugin>
72             <artifactId>maven-war-plugin</artifactId>
73             <configuration>
74                 <version>2.5</version>
75                  <webXml>src\main\webapp\WEB-INF\web.xml</webXml>
76             </configuration>
77         </plugin>
78           <plugin>
79               <groupId>org.codehaus.mojo</groupId>
80               <artifactId>tomcat-maven-plugin</artifactId>
81               <version>1.1</version>
82               <configuration>
83                   <!-- <warFile>target/serverdemo.war</warFile> -->
84                   <server>${tomcat.server}</server>
85                   <url>http://192.168.234.9:8080/manager/text</url>
86                   <path>/${warPackageName}</path>
87               </configuration>
88           </plugin>
89       </plugins>
90   </build>
91    
92 </project>

1、build

Server:用来指定到哪个服务器,${}获取properties中的变量tomcat,然后调用settings.xml文件中配置的tomcat和用户名、密码(上一节)

url:用来指定发布到服务器的地址,h后面必须跟text

path:即部署到服务器的项目名,这里是webapps/MyWebAppDemo.war.访问路径http://192.168.234.9:8080/MyWebAppDemo

profile:

Server变量有三种配置方式:

a、

<properties>
        <warPackageName>MyWebAppDemo</warPackageName>
        <tomcat.deploy.server>localTestServer</tomcat.deploy.server>     
<tomcat.deploy.serverUrl>http://localhost/manager/text</tomcat.deploy.serverUrl> </properties>

b、

<profiles>
        <profile>
            <id>deploy2production</id>
            <properties>
                <tomcat.deploy.server>productionServer</tomcat.deploy.server>               
<tomcat.deploy.serverUrl>http://120.26.93.30:8080/manager/text</tomcat.deploy.serverUrl> </properties> </profile> </profiles>

c、

<plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
            <configuration>
                <port>8089</port>
                <path>/</path>
                <url>http://192.168.234.9:8080/manager/text</url>
                <username>admin</username>
                <password>admin</password>
                <update>true</update> 
         </configuration>
</plugin>

2、UTF-8编码问题

3、Spring框架冲突问题

因为既依赖dubbo框架,又依赖spring框架,导致报错(一般报NoSuchMethodError都是因为依赖冲突)

22-Oct-2016 01:17:46.438 信息 [http-nio-8080-exec-11] org.apache.catalina.core.ApplicationContext.log No Spring WebApplicationInitializer types detected on classpath
22-Oct-2016 01:17:46.550 严重 [http-nio-8080-exec-11] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
 java.lang.NoSuchMethodError: org.springframework.core.CollectionFactory.createConcurrentMapIfPossible(I)Ljava/util/Map;

解决方法:

 <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>dubbo</artifactId>
        <version>2.5.3</version>
        <exclusions>             
         <exclusion>                
          <groupId>org.springframework</groupId>                
          <artifactId>spring</artifactId>             
         </exclusion>         
    </exclusions>    
 </dependency>

4、web.xml问题

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project test-maven-server-console: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]

[ERROR]

[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.

[ERROR] Re-run Maven using the -X switch to enable full debug logging.

[ERROR]

[ERROR] For more information about the errors and possible solutions, please read the following articles:

解决方法:手动配置读取web.xml

<plugin>
       <artifactId>maven-war-plugin</artifactId>
       <configuration>
              <version>2.5</version>
              <webXml>src\main\webapp\WEB-INF\web.xml</webXml>
        </configuration>
</plugin>

5、Maven clean导致引入jar文件没有编译的问题

[ERROR] /F:/stsProjects/test-maven-server-console/src/main/java/com/test/dubbo/controller/IndexController.java:[8,39] 程序包com.test.dubbo.registry.service不存在

[ERROR] /F:/stsProjects/test-maven-server-console/src/main/java/com/test/dubbo/controller/IndexController.java:[14,17] 找不到符号

  符号:   类 TestRegistryService

  位置: 类 com.test.dubbo.controller.IndexController

6、Maven默认使用jdk1.5的问题

7、web项目不存在src/main/webapp目录的问题

右键项目—Build Path -- Configure Build Path –Libraries –双击JRE System Liaraies – 在Execution environment选择合适版本

完整的项目目录:

结合实际项目分析pom.xml _ JavaClub全栈架构师技术笔记

 

作者:impwang
来源链接:https://www.cnblogs.com/wangwanchao/p/6231264.html

版权声明:
1、Java侠(https://www.javaxia.com)以学习交流为目的,由作者投稿、网友推荐和小编整理收藏优秀的IT技术及相关内容,包括但不限于文字、图片、音频、视频、软件、程序等,其均来自互联网,本站不享有版权,版权归原作者所有。

2、本站提供的内容仅用于个人学习、研究或欣赏,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵犯相关权利人及本网站的合法权利。
3、本网站内容原作者如不愿意在本网站刊登内容,请及时通知本站(javaclubcn@163.com),我们将第一时间核实后及时予以删除。





本文链接:https://www.javaxia.com/server/125290.html

分享给朋友: