3

Good evening!

Using Cargo via Maven, I've configured my pom.xml to create an instance of glassfish and then deploy my project to it, before running integration tests. I'm most of the way there, in that I've got my code deployed, I've setup a datasource and a JNDI resource for it, but when I attempt to actually use the resource, I get the following exception:

Wrong class name or classpath for Datasource Object 
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

On a regular installation of glassfish, I can easily install the connector, but the installation of glassfish in this case is automated and a new instance is created each time I run the tests.

Is there any way that I can provide the mysql connector, either on a classpath that glassfish can read, or by installing it in the new instance of glassfish that's created each build?

Thanks!

Steven Bakhtiari
  • 3,227
  • 2
  • 20
  • 24
  • Why can't you put the jar in WEB-INF/lib? Otherwise it may be possible to copy the jar with maven to the glassfish lib dir before you start the server. – unwichtich Jan 14 '13 at 23:48
  • I don't want to deploy it with my application... I did just figure out the answer, though. I found something eventually, just a shame the Cargo docs are all over the place. – Steven Bakhtiari Jan 14 '13 at 23:52

1 Answers1

2

Scouring the docs a little more, I found out that I can do this by providing maven dependencies in the container configuration, like so:

<configuration>
    <container>
        <containerId>glassfish3x</containerId>
        <artifactInstaller>
            <groupId>org.glassfish.main.distributions</groupId>
            <artifactId>glassfish</artifactId>
            <version>${glassfish.version}</version>
        </artifactInstaller>
        <dependencies>
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
            </dependency>
        </dependencies>
    </container>
    <configuration>
        <properties>
            <cargo.datasource.datasource.mysql>
                cargo.datasource.jndi=jdbc/MysqlPool|
                cargo.datasource.driver=com.mysql.jdbc.Driver|
                cargo.datasource.url=jdbc:mysql://localhost/databasename|
                cargo.datasource.transactionsupport=LOCAL_TRANSACTION|
                cargo.datasource.username=username|
                cargo.datasource.password=password
            </cargo.datasource.datasource.mysql>
        </properties>
    </configuration>
</configuration>

Take note of the mysql dependency. It needs to reference a dependency already defined in my project (which, for my project has a scope of "provided"). This works as expected. :)

Steven Bakhtiari
  • 3,227
  • 2
  • 20
  • 24