如何使用Maven Cargo在Glassfish中设置配置(JDBC Realm或Java Mail Session)?

我使用Maven Cargo(1.2.1)配置并启动Glassfish 3.1.2进行集成测试.我能够配置数据源并启动服务器.但我还需要配置JDBC安全领域以及Java Mail Session.

但我不知道如何使用maven货物配置安全领域和Java邮件会话,是否有人有想法?

一种方法可能是使用asadmin但我不知道如何从货物中使用它.

到目前为止我所拥有的:

<plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
    <version>1.2.1</version>
    <executions>
        <execution>
            <id>start-container</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>start</goal>
            </goals>
        </execution>
        <execution>
            <id>stop-container</id>
            <phase>post-integration-test</phase>
            <goals>
                <goal>stop</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <container>
            <type>installed</type>
            <containerId>glassfish3x</containerId>
            <artifactInstaller>
                <groupId>org.glassfish.main.distributions</groupId>
                <artifactId>glassfish</artifactId>
                <version>3.1.2</version>
                <type>zip</type>
            </artifactInstaller>
            <output>${project.build.directory}/glassfish/container.log</output>
            <log>${project.build.directory}/glassfish/cargo.log</log>
            <append>false</append>
            <dependencies>
                <dependency>
                    <groupId>com.oracle</groupId>
                    <artifactId>ojdbc</artifactId>
                </dependency>
            </dependencies>
        </container>
        <configuration>
            <home>${project.build.directory}/cargo/configurations/glassfish</home>
            <properties>
                <cargo.servlet.port>8082</cargo.servlet.port>
                <cargo.datasource.datasource>
                    cargo.datasource.jndi=jdbc/tecisplus|
                    cargo.datasource.type=javax.sql.DataSource|
                    cargo.datasource.driver=oracle.jdbc.OracleDriver|
                    cargo.datasource.url=${it-database.url}|
                    cargo.datasource.username=$[it-database.username}|
                    cargo.datasource.password=${it-database.password}
                </cargo.datasource.datasource>
            </properties>
            <deployables>
                <deployable>
                    <groupId>de.test</groupId>
                    <artifactId>test-ear</artifactId>
                    <type>ear</type>
                </deployable>
            </deployables>
        </configuration>
    </configuration>
</plugin>

解决方法:

我现在使用的解决方法是手写的domain.xml文件已经包含所有配置(JDBC,Realm和JavaMail会话).

然后我指示货物使用domain.xml而不是自己配置:

<configuration>
    <home>${project.build.directory}/cargo/configurations/glassfish</home>
    <configfiles>
        <configfile>
            <file>${project.build.directory}/filtered-serverresources/domain.xml</file>
            <todir>cargo-domain/config</todir>
        </configfile>
    </configfiles>
    <deployables>
        <deployable>
            <groupId>de.tecis.tecisplus</groupId>
            <artifactId>tecisplus-ear</artifactId>
            <type>ear</type>
        </deployable>
    </deployables>
</configuration>

${project.build.directory} /filtered-serverresources/domain.xml是一个配置文件的小技巧(货物也可以替换一些属性,但我无法替换货物不知道的属性.)所以我使用maven-resource-plugin

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <!-- because maven test-resource does not support filter! -->
    <version>2.5</version>
    <configuration>
        <encoding>UTF-8</encoding>
    </configuration>
    <executions>
        <execution>
            <id>filter-glassfish-configuration-domain-file</id>
            <!-- <phase>pre-integration-test</phase> -->
            <phase>process-test-resources</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.directory}/filtered-serverresources</outputDirectory>
                <resources>
                    <resource>
                        <directory>src/test/serverresources</directory>
                        <filtering>true</filtering>
                        <includes>
                            <include>**/*.xml</include>
                        </includes>
                    </resource>
                </resources>
                <delimiters>
                    <delimiter>~{*}</delimiter>
                </delimiters>
            </configuration>
        </execution>
    </executions>
</plugin>

修改后的分隔符〜{…}是nesseary,因为domain.xml包含许多看起来像默认分隔符${…}的序列

上一篇:学习新时代编程语言Rust-8复合基本数据类型练习


下一篇:全栈程序员的新玩具Rust(三)板条箱