多个容器上的Maven部署

时间:2012-06-24 11:44:38

标签: maven-2 junit glassfish

我想知道如何在Maven中定义多个容器,一个用于开发和调试,一个用于生产。例如:

  1. 具有JUnit依赖关系的嵌入式Glassfish
  2. 在没有测试的情况下部署在Glassfish服务器上(不需要自动部署,我只是手动复制到域中)。
  3. 因此,当我运行JUnit测试时,我会做类似的事情:

    mvn test -P junit
    

    用于构建要部署的包

    mvn package -P webapp
    

    我正在用-P开关编写示例,因为到目前为止我已经提出了这个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/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>se.while</groupId>
        <artifactId>project</artifactId>
        <packaging>war</packaging>
        <version>1.0-SNAPSHOT</version>
        <name>project Maven Webapp</name>
        <url>http://maven.apache.org</url>
    
        <profiles>
            <profile>
                <id>junit</id>
                <dependencies>
                    <dependency>
                        <groupId>junit</groupId>
                        <artifactId>junit</artifactId>
                        <version>4.8.1</version>
                        <scope>test</scope>
                    </dependency>               
                    <dependency>
                        <groupId>org.glassfish.main.extras</groupId>
                        <artifactId>glassfish-embedded-all</artifactId>
                        <version>3.1.2</version>
                        <scope>provided</scope>
                    </dependency>
                </dependencies>
            </profile>
            <profile>
                <id>webapp</id>
                <dependencies>
                    <dependency>
                        <groupId>org.eclipse.persistence</groupId>
                        <artifactId>javax.persistence</artifactId>
                        <version>2.0.0</version>
                    </dependency>
                    <dependency>
                        <groupId>org.eclipse.persistence</groupId>
                        <artifactId>eclipselink</artifactId>
                        <version>2.3.2</version>
                    </dependency>
                    <dependency>
                        <groupId>javax.faces</groupId>
                        <artifactId>jsf-api</artifactId>
                        <version>2.1</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>org.glassfish</groupId>
                        <artifactId>javax.ejb</artifactId>
                        <version>3.1</version>
                        <scope>provided</scope>
                    </dependency>
                    <dependency>
                        <groupId>org.primefaces</groupId>
                        <artifactId>primefaces</artifactId>
                        <version>3.3.1</version>
                    </dependency>
                </dependencies>
    
            </profile>
        </profiles>
    
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>org.jboss.arquillian</groupId>
                    <artifactId>arquillian-bom</artifactId>
                    <version>1.0.1.Final</version>
                    <scope>import</scope>
                    <type>pom</type>
                </dependency>
            </dependencies>
        </dependencyManagement>
    
    
        <repositories>
            <repository>
                <id>EclipseLink Repo</id>
                <url>http://www.eclipse.org/downloads/download.php?r=1&amp;nf=1&amp;file=/rt/eclipselink/maven.repo</url>
                <!-- use this for javax.persistence <snapshots> <enabled>true</enabled></snapshots> -->
            </repository>
    
            <repository>
                <id>prime-repo</id>
                <name>PrimeFaces Maven Repository</name>
                <url>http://repository.primefaces.org</url>
                <layout>default</layout>
            </repository>
        </repositories>
    
        <build>
            <finalName>project</finalName>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    
    
    </project>
    

    我现在有2个问题(至少):

    1. 测试似乎与“mvn test -P junit”一起工作但是当我 做“mvn包-P webapp”Maven似乎再次运行测试(用 没有容器我假设也没有junit依赖)。
    2. Eclipse IDE lint检查程序确实指示源代码中的错误 取决于激活的配置文件例如,如果我激活了webapp 配置文件,所有测试类都将出错。
    3. 你能指导我吗?

      祝你好运

1 个答案:

答案 0 :(得分:1)

添加到此

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.12</version>
        <configuration>
          <skipTests>${skip.junit.tests}</skipTests>
        </configuration>
      </plugin>  

webapp 个人资料添加

<properties>
   <skip.junit.tests>true</skip.junit.tests>
</properties> 

junit 个人资料添加

<properties>
   <skip.junit.tests>false</skip.junit.tests>
</properties>
相关问题