9

I want to have a way to run maven so that it will:

  • start a WildFly server instance in standalone mode (wildfly:run)
  • deploy the hsqldb driver
  • add a datasource
  • deploy the application

The problem is that:

  • wildfly:run blocks so no other maven goals can be executed
  • the server instance must be running before it can be configured or an app can be deployed (daaa)

A possible work around that comes to my mind is:

  • wildfly:start
  • configure the server and deploy the app
  • block until the user presses CTRL-C, is there a maven plugin that does that?
Adam Siemion
  • 15,569
  • 7
  • 58
  • 92
  • 1
    I'm having the exact same issue. mvn wildfly:start does not block. Were you able to come up with a solution? – fansonly Dec 05 '14 at 20:20
  • 1
    @fansonly No, I came up with some workaround that I do not remember now, but not an ultimate solution. If you have time I encourage you to deliver the new feature (https://github.com/wildfly/wildfly-maven-plugin) that James has mentioned in his answer - a configuration property to not register the shutdown hook and leave the process running. – Adam Siemion Dec 05 '14 at 20:41
  • I will look in to doing that if the project manager gives me the time. – fansonly Dec 05 '14 at 22:56

3 Answers3

4

You can use the parameter beforeDeployment of the run goal (source):

<plugin>
    <groupId>org.wildfly.plugins</groupId>
    <artifactId>wildfly-maven-plugin</artifactId>
    <configuration>
        <beforeDeployment>
            <commands>
                <command>data-source add --jndi-name=java:jboss/datasources/OracleDS --name=testDB --connection-url=jdbc:h2:mem:test;DB_CLOSE_DELAY=-1 --driver-name=h2 --user-name=sa --password=sa</command>
            </commands>
        </beforeDeployment>
    </configuration>
</plugin>

If you need additional libraries for your database driver you can do something like that (source):

module add --name=org.postgres --resources=/tmp/postgresql-9.3-1101.jdbc41.jar --dependencies=javax.api,javax.transaction.api
/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgres",driver-class-name=org.postgresql.Driver)
Community
  • 1
  • 1
CSchulz
  • 10,882
  • 11
  • 60
  • 114
2

The wildfly:start goal will not block and it has a shutdown hook to destroy the process once maven exits. It may be worth adding a configuration property to not register the shutdown hook and leave the process running.. ..but I'm getting off topic.

Since maven runs goals based on a lifecycle phase you could invoke the start and deploy goal in a phase that runs before the package phase. The run goal requires the package phase so anything before that should work.

James R. Perkins
  • 16,800
  • 44
  • 60
  • I have tried that, but when `wildfly:run` is executed after `wildfly:start` it tries to start a new WildFly instance using the same ports, what of course fails. – Adam Siemion Sep 18 '14 at 07:34
1

I don't quite understand what your use case is or why wildfly:start followed by wildfly:deploy is not enough.

Are you doing manual or automatic testing?

For integration testing, if wildfly-maven-plugin does not suit your needs, have a look at Cargo and its Maven and WildFly support.

Harald Wellmann
  • 12,615
  • 4
  • 41
  • 63
  • because `wilfdly:start` does not block, so once `wildfly:start` and `wildfly:deploy` is completed the started WildFly instance will be shut down. – Adam Siemion Sep 14 '14 at 09:02