简体   繁体   中英

why when l use maven to build myeclipse web project,it doesn't copy “test” package to tomcat?

l am developing a web project based on maven using myeclipse. now, l am testing my project. Project Structure:

but when l deploy the project to tomcat 7, l found a problem. that is,in tomcat7/webapps/partysys,there is no "com.partysys.test" package but have "com.party.core" package!why? l want to know! beacuse no com.party.test,so when l start tomcat7,it errors.

l configure pom.xml to deploy my project to tomcat7 automatically.

<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.partysys</groupId>
  <artifactId>party</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>party Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
            <scope>test</scope>
        </dependency>
        <!-- Struts2 -->
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-core</artifactId>
            <version>2.3.24</version>
        </dependency>

        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-spring-plugin</artifactId>
            <version>2.3.24.1</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.2.2.Final</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>4.2.4.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>4.2.4.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>4.2.4.RELEASE</version>
        </dependency>


        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>4.2.4.RELEASE</version>
        </dependency>

        <!--  ApplicationContextInitializer -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.2.4.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.8.7</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.26</version>
        </dependency>

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


        <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>
        <dependency>
            <groupId>javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.11.0.GA</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>javax.servlet.jsp-api</artifactId>
            <version>2.3.1</version>
        </dependency>
    </dependencies>

  <build>
    <finalName>partysys</finalName>
    <pluginManagement>
        <plugins>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-compiler-plugin</artifactId>
                 <version>3.2</version>
                 <configuration>
                     <source>1.8</source>
                     <target>1.8</target>
                 </configuration>
             </plugin>
             <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.4</version>
                    <configuration>
                        <warSourceDirectory>src/main/webapp</warSourceDirectory>
                        <warName>party</warName>
                        <failOnMissingWebXml>false</failOnMissingWebXml>
                    </configuration>
             </plugin>
             <plugin>
                 <groupId>org.apache.tomcat.maven</groupId>
                 <artifactId>tomcat7-maven-plugin</artifactId>
                 <version>2.2</version>
                 <configuration>
                     <path>/${project.build.finalName}</path>
                     <server>tomcat7</server>
                     <username>admin</username>
                     <password>admin</password>
                     <url>http://localhost:8425/manager/text</url>
                  </configuration>
             </plugin>
        </plugins>
    </pluginManagement>
  </build>
   <repositories>
        <repository> 
            <id>people.apache.snapshots</id> 
            <url> 
                http://repository.apache.org/content/groups/snapshots-group/ 
            </url> 
            <releases> 
                <enabled>false</enabled> 
            </releases> 
            <snapshots> 
                <enabled>true</enabled> 
            </snapshots> 
        </repository> 
    </repositories>
    <!-- 插件库 -->
    <pluginRepositories>
        <pluginRepository> 
            <id>apache.snapshots</id> 
            <name>Apache Snapshots</name> 
            <url> 
                http://repository.apache.org/content/groups/snapshots-group/ 
            </url> 
            <releases> 
                <enabled>false</enabled> 
            </releases> 
            <snapshots> 
                <enabled>true</enabled> 
            </snapshots> 
        </pluginRepository>
    </pluginRepositories>
</project>

maven/conf/settings.xml:

<server> 
       <id>tomcat7</id> 
       <username>admin</username> 
       <password>admin</password> 
    </server>

tomcat/conf/tomcat-users.xml:

 <role rolename="tomcat"/>
  <role rolename="manager"/>
  <role rolename="manager-gui"/>
  <role rolename="manager-script" />
  <role rolename="admin-gui"/>
  <role rolename="manager-jmx"/>
  <user username="tomcat" password="tomcat" roles="tomcat,manager,manager-script,admin-gui" />
  <user username="admin" password="admin" roles="manager-script,manager-jmx" />

My guess is that some maven plugin is confused about your package name (test) and does not include it into your final war/jar.

Two suggestions: 1) refactor your package name. Could you change it from com.partysys.test to com.partysys.check ? (or anything else) 2) review your effective pom.

In eclipse, double-click your pom.xml . Among others, it will show to you a Effective POM , that is the pom that will be used. Review it and try to find if it has some instructions related to test (surefire plugin).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM