为什么当我使用maven构建myeclipse web项目时,它不会将“test”包复制到tomcat?

时间:2017-04-02 01:58:13

标签: java eclipse maven tomcat

我正在使用myeclipse开发基于maven的web项目。 现在,我正在测试我的项目。 Project Structure:

但是当我将项目部署到tomcat 7时,我发现了一个问题。 也就是说,在tomcat7 / webapps / partysys中,没有“com.partysys.test”包,但有“com.party.core”包!为什么?我想知道! beacuse no com.party.test,所以当我启动tomcat7时,它会出错。

配置pom.xml以自动将我的项目部署到tomcat7。

<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>

行家/ 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" />

1 个答案:

答案 0 :(得分:0)

我的猜测是,某些maven插件对您的包名称(测试)感到困惑,并且不会将其包含在您的最终战争/ jar中。

两个建议:1)重构你的包名。您可以将其从com.partysys.test更改为com.partysys.check吗? (或其他任何事情)2)检查你的有效pom。

在eclipse中,双击pom.xml。其中,它将向您显示有效POM ,即将使用的pom。查看它并尝试查找它是否有一些与测试相关的指令(surefire插件)。