Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Maven testResources未应用于多模块/概要文件项目_Java_Postgresql_Maven_Intellij 13 - Fatal编程技术网

Java Maven testResources未应用于多模块/概要文件项目

Java Maven testResources未应用于多模块/概要文件项目,java,postgresql,maven,intellij-13,Java,Postgresql,Maven,Intellij 13,我有一个Maven多模块/概要项目,在运行测试模块时,它的测试资源显然没有被应用。这些资源定义应用程序将使用的数据库(一个是我的create.sql脚本文件): “项目”结构为: project/ pom.xml //packing: pom | +-- core/ pom.xml //packing: war | +-- module-a/ pom.xml //packing: jar | +-- module-b/ pom.xml //packing: jar | +-- test/ pom

我有一个Maven多模块/概要项目,在运行测试模块时,它的测试资源显然没有被应用。这些资源定义应用程序将使用的数据库(一个是我的create.sql脚本文件):

“项目”结构为:

project/ pom.xml //packing: pom
|
+-- core/ pom.xml //packing: war
|
+-- module-a/ pom.xml //packing: jar
|
+-- module-b/ pom.xml //packing: jar
|
+-- test/ pom.xml //packing: jar
        +-- ** src/test/resources/create.sql **
根“项目”pom定义为:

<?xml ... maven-4.0.0.xsd">

<!-- ... -->
<packaging>pom</packaging>

<properties>
    <!-- global properties -->
</properties>

<modules>
    <module>core</module>
    <module>module-a</module>
    <module>module-b</module>
    <module>test</module> <!-- CAN BE REMOVED -->
</modules>

<repositories>
    <!-- some repo declarations -->
</repositories>

<dependencies>
    <!-- all general dependencies -->
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
</build>

致以最诚挚的问候。

我已经在我认为理想的方法(使用测试模块)和实际解决方案(生成构建或执行集成测试的maven任务)之间找到了一个部分解决方案

因此,我将测试类和资源从测试模块移动到war模块,并删除了父pom中的模块测试。

<?xml ... maven-4.0.0.xsd">

<!-- ... -->
<packaging>pom</packaging>

<properties>
    <!-- global properties -->
</properties>

<modules>
    <module>core</module>
    <module>module-a</module>
    <module>module-b</module>
    <module>test</module> <!-- CAN BE REMOVED -->
</modules>

<repositories>
    <!-- some repo declarations -->
</repositories>

<dependencies>
    <!-- all general dependencies -->
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
</build>
<?xml ... maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
    <!-- 'project' is the parent -->
</parent>

<!-- ... -->
<packaging>war</packaging>

<profiles>
    <profile>
        <id>dev-a</id>
        <properties>
            <profileName>dev-a</profileName>
            **<db.name>db</db.name>**
            <skipTests>true</skipTests>
        </properties>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <dependencies>
            <dependency>
                <groupId>...</groupId>
                <artifactId>module-a</artifactId>
                <version>1.0-SNAPSHOT</version>
            </dependency>
        </dependencies>
    </profile>
    <profile>
        <id>dev-b</id>
        <properties>
            <profileName>dev-b</profileName>
            **<db.name>db</db.name>**
            <skipTests>true</skipTests>
        </properties>
        <dependencies>
            <dependency>
                <groupId>...</groupId>
                <artifactId>module-b</artifactId>
                <version>1.0-SNAPSHOT</version>
            </dependency>
        </dependencies>
    </profile>
    <profile>
        <id>test-a</id>
        <properties>
            <profileName>test-a</profileName>
            **<db.name>db_test</db.name>**
            <selenium.context>http://127.0.0.1:9999/${profileName}</selenium.context>
        </properties>
        <dependencies>
            <dependency>
                <groupId>...</groupId>
                <artifactId>module-a</artifactId>
                <version>1.0-SNAPSHOT</version>
            </dependency>
        </dependencies>
    </profile>
    <profile>
        <id>test-b</id>
        <properties>
            <profileName>test-b</profileName>
            **<db.name>db_test</db.name>**
            <selenium.context>http://127.0.0.1:9999/${profileName}</selenium.context>
        </properties>
        <dependencies>
            <dependency>
                <groupId>...</groupId>
                <artifactId>module-b</artifactId>
                <version>1.0-SNAPSHOT</version>
            </dependency>
        </dependencies>
    </profile>
</profiles>

<build>
    <finalName>${profileName}##${app.version}.${maven.build.timestamp}</finalName>
    <plugins>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.5</version>
            <configuration>
                <attachClasses>true</attachClasses>
                <failOnMissingWebXml>false</failOnMissingWebXml>
                <useCache>false</useCache>
                <archive>
                    <manifest>                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                    </manifest>
                    <manifestEntries>
                        <Implementation-Version>${project.artifactId}#${maven.build.timestamp}</Implementation-Version>
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>
    </plugins>

    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
            <includes>
                <include>**/*</include>
            </includes>
        </resource>
    </resources>
    <testResources>
        <testResource>
            <directory>src/test/resources</directory>
            <filtering>true</filtering>
            <includes>
                <include>**/*</include>
            </includes>
        </testResource>
    </testResources>
</build>
<?xml ... maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
    <!-- 'project' is the parent -->
</parent>

<artifactId>module-a</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<?xml  ... maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
    <!-- 'project' is the parent -->
</parent>

<!-- ... -->
<packaging>jar</packaging>

<dependencies>
    <!-- All test dependencies + ... -->
    <dependency>
        <groupId>...</groupId>
        <artifactId>module-a</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>...</groupId>
        <artifactId>module-b</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>...</groupId>
        <artifactId>core</artifactId>
        <version>1.0-SNAPSHOT</version>
        <classifier>classes</classifier>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <executions>
                <execution>
                    <goals>
                        <goal>test-jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.17</version>
            <configuration>
                <includes>
                    <include>**/*IT.java</include>
                </includes>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.17</version>
            <executions>
                <execution>
                    <id>default-test</id>
                    <configuration>
                        <skipTests>true</skipTests>
                    </configuration>
                </execution>

                <execution>
                    <id>surefire-it</id>
                    <phase>integration-test</phase>
                    <goals>
                        <goal>test</goal>
                    </goals>
                    <configuration>
                        <skipTests>false</skipTests>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <server>Tomcat 7</server>
                <path>/${project.artifactId}</path>
            </configuration>
            <executions>
                <execution>
                    <id>start-tomcat</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>run-war-only</goal>
                    </goals>
                    <configuration>
                        <fork>true</fork>
                        <port>9999</port>
                    </configuration>
                </execution>
                <execution>
                    <id>stop-tomcat</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>shutdown</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.7</version>
            <executions>
                <execution>
                    <id>start-selenium</id>
                    <phase>pre-integration-test</phase>
                    <configuration>
                        <target>
                            <exec executable="cmd.exe" spawn="true">
                                <arg value="/u/c" />
                                <arg value="${basedir}/src/test/resources/start-selenium.bat" />
                                <arg line="${basedir}/target/${project.build.finalName}/WEB-INF/lib/selenium-server-standalone-${selenium.version}.jar" />
                                <arg line="-timeout 30 -port 4444" />
                            </exec>
                        </target>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
runnig dev-a: A war file using db + module-a.jar
runnig dev-b: A war file using db + module-b.jar
runnig test-a: A war file using db_test + module-a.jar + test-jar using the same database db_test
runnig test-b: A war file using db_test + module-b.jar + test-jar using the same database db_test