src / main / resources未在war类路径中添加

时间:2017-03-30 16:11:17

标签: java eclipse hibernate maven tomcat8

我开发了一个web + maven项目。所有开发都已完成。现在我正在尝试部署生产。我遇到的问题是src/main/resources文件夹中没有添加ProjectName.war/WEB-INF/classes/的内容。检查屏幕截图

Incident Management

类似hibernate.cfg.xml不存在,其他文件/文件夹也不在类路径中(ProjectName.war/WEB-INF/classes/)。我错过了任何插件吗?我认为src/main/resources的内容应根据this link自动添加。

的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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>IncidentManagement</groupId>
    <artifactId>IncidentManagement</artifactId>
    <version>1</version>
    <packaging>war</packaging>
    <build>
        <sourceDirectory>src.main.java</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <warSourceDirectory>WebContent</warSourceDirectory>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <properties>
        <java.version>1.8</java.version>
        <junit.version>4.12</junit.version>
        <servlet.version>3.1.0</servlet.version>
        <mojarra.version>2.2.12</mojarra.version>
        <primefaces.version>5.3</primefaces.version>
        <maven.compiler.plugin.version>3.3</maven.compiler.plugin.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <repositories>
        <repository>
            <id>JBoss repository</id>
            <url>http://repository.jboss.org/nexus/content/groups/public/</url>
        </repository>
    </repositories>

    <dependencies>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.2</version>
            <scope>test</scope>
        </dependency>

        <!-- ORACLE database driver -->

        <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
        <!-- <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.38</version>
        </dependency>  -->

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>3.6.3.Final</version>
        </dependency>

        <dependency>
            <groupId>dom4j</groupId>
            <artifactId>dom4j</artifactId>
            <version>1.6.1</version>
        </dependency>

        <dependency>
            <groupId>javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.12.1.GA</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>${servlet.version}</version>
            <scope>provided</scope>
        </dependency>
        <!-- Mojarra JSF -->
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>${mojarra.version}</version>
        </dependency>
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>${mojarra.version}</version>
        </dependency>
        <!-- PrimeFaces -->
        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>${primefaces.version}</version>
        </dependency>

        <!-- Excel and CSV -->

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.10-FINAL</version>
            <type>jar</type>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.10-FINAL</version>
            <type>jar</type>
        </dependency>

        <!-- PDF -->

        <dependency>
            <groupId>com.lowagie</groupId>
            <artifactId>itext</artifactId>
            <version>2.1.7</version>
        </dependency>

        <!-- JSON -->
        <dependency>
           <groupId>com.googlecode.json-simple</groupId>
           <artifactId>json-simple</artifactId>
           <version>1.1.1</version>
        </dependency>

        <!-- Primefaces Theme -->
        <!-- https://mvnrepository.com/artifact/org.primefaces.extensions/all-themes -->
        <dependency>
            <groupId>org.primefaces.extensions</groupId>
            <artifactId>all-themes</artifactId>
            <version>1.0.8</version>
        </dependency>


    </dependencies>

</project>

3 个答案:

答案 0 :(得分:0)

您的文件夹结构错误,应该是src/main/javasrc/test/java ..以及src.main.java所拥有的内容。请从开始使用以下命令重新创建maven项目

enter image description here

mvn archetype:generate -DgroupId=IncidentManagement
   -DartifactId=IncidentManagement
   -DarchetypeArtifactId=maven-archetype-quickstart
   -DinteractiveMode=false

答案 1 :(得分:0)

尝试:

  1. 创建名为src / main / java的新文件夹,src / main / resources src / test / java src / test / resources和src / main / webapp
  2. 之后将所有课程/文件移到各自的文件夹中,删除错误文件夹
  3. 右键单击文件夹src / main / java等,然后选择 - &gt; Build Path - &gt; Use as as Source Folder。
  4. 在src / main / reources中创建META-INF文件夹,您可以在其中放置MANIFEST.MF或persistence.xml等文件。
  5. 在src / main / webapp中创建两个文件夹:META-INF和WEB-INF;在META-INF上你可以把文件像MANIFEST.MF,在WEB-INF中你可以放置像web.xml这样的文件

答案 2 :(得分:0)

首先检查资源是否在IDE的构建路径中。如果是,则从您的pom中删除maven-war-plugin,然后再次尝试构建和部署。它可能会奏效。