Как настроить конфигурацию (JDBC Realm или Java Mail Session) в Glassfish с Maven Cargo?

Я использую Maven Cargo (1.2.1) для настройки и запуска Glassfish 3.1.2 для интеграционных тестов. Я могу настроить источник данных и запустить сервер. Но мне также нужно настроить область безопасности JDBC, а также сеанс почты Java.

Но я понятия не имею, как настроить область безопасности и сеанс почты Java с maven cargo, у кого-нибудь есть идея?

Одним из способов, возможно, является использование 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>

1 ответ

Решение

Обходной путь, который я использую в данный момент, так что написано от руки domain.xml файл, который уже содержит всю конфигурацию (JDBC, Realm и JavaMail Session).

Затем я поручил грузу использовать это 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>

Модифицированный разделитель ~{ ... } являются необходимыми, потому что domain.xml содержит много последовательностей, которые выглядят как разделитель по умолчанию ${...}

Другие вопросы по тегам