Installing a JDBC driver from a private secured maven repo into Wildfly Swarm

672 views Asked by At

I'm trying to install an Oracle JDBC driver into Wildfly Swarm (2016.12.0) using the Java Configuration API. The driver jar is correctly installed in a remote, private, secured maven repository. I'm basically following the example here:

https://github.com/wildfly-swarm/wildfly-swarm-examples/tree/master/datasource/datasource-subsystem

I have a src/main/resources/modules/com/oracle/ojdbc/main directory in my project with the following module.xml file:

<module xmlns="urn:jboss:module:1.3" name="com.oracle.ojdbc">

    <resources>
        <artifact name="my.repo.group.id:ojdbc6:11.2.0.1.0"/>    
    </resources>

    <dependencies>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>
    </dependencies>
</module>

Here's the snippet of configuration code I'm using:

Swarm swarm = new Swarm();

DatasourcesFraction datasources = new DatasourcesFraction().jdbcDriver("oracle-ojdbc-xa", (d) -> {
    d.xaDatasourceClass("oracle.jdbc.xa.client.OracleXADataSource");
    d.driverModuleName("com.oracle.ojdbc");
});

swarm.fraction(datasources);
swarm.start();
swarm.deploy();

Here's the exception I'm getting:

2016-12-17 13:25:49,138 ERROR [stderr] (ServerService Thread Pool -- 28) org.jboss.modules.ModuleLoadException: Error loading module from modules/com/oracle/ojdbc/main/module.xml
[0m[31m2016-12-17 13:25:49,139 ERROR [stderr] (ServerService Thread Pool -- 28)     at org.jboss.modules.xml.ModuleXmlParser.parseModuleXml(ModuleXmlParser.java:228)
[0m[31m2016-12-17 13:25:49,139 ERROR [stderr] (ServerService Thread Pool -- 28)     at org.wildfly.swarm.bootstrap.modules.BootstrapClasspathModuleFinder.findModule(BootstrapClasspathModuleFinder.java:58)
[0m[31m2016-12-17 13:25:49,139 ERROR [stderr] (ServerService Thread Pool -- 28)     at org.jboss.modules.ModuleLoader.findModule(ModuleLoader.java:439)
[0m[31m2016-12-17 13:25:49,139 ERROR [stderr] (ServerService Thread Pool -- 28)     at org.jboss.modules.ModuleLoader.loadModuleLocal(ModuleLoader.java:342)
[0m[31m2016-12-17 13:25:49,139 ERROR [stderr] (ServerService Thread Pool -- 28)     at org.jboss.modules.ModuleLoader.preloadModule(ModuleLoader.java:289)
[0m[31m2016-12-17 13:25:49,139 ERROR [stderr] (ServerService Thread Pool -- 28)     at org.jboss.modules.ModuleLoader.loadModule(ModuleLoader.java:221)
[0m[31m2016-12-17 13:25:49,139 ERROR [stderr] (ServerService Thread Pool -- 28)     at org.jboss.as.connector.subsystems.datasources.JdbcDriverAdd.performRuntime(JdbcDriverAdd.java:98)
[0m[31m2016-12-17 13:25:49,139 ERROR [stderr] (ServerService Thread Pool -- 28)     at org.jboss.as.controller.AbstractAddStepHandler.performRuntime(AbstractAddStepHandler.java:337)
[0m[31m2016-12-17 13:25:49,139 ERROR [stderr] (ServerService Thread Pool -- 28)     at org.jboss.as.controller.AbstractAddStepHandler$1.execute(AbstractAddStepHandler.java:151)
[0m[31m2016-12-17 13:25:49,140 ERROR [stderr] (ServerService Thread Pool -- 28)     at org.jboss.as.controller.AbstractOperationContext.executeStep(AbstractOperationContext.java:890)
[0m[31m2016-12-17 13:25:49,140 ERROR [stderr] (ServerService Thread Pool -- 28)     at org.jboss.as.controller.AbstractOperationContext.processStages(AbstractOperationContext.java:659)
[0m[31m2016-12-17 13:25:49,140 ERROR [stderr] (ServerService Thread Pool -- 28)     at org.jboss.as.controller.AbstractOperationContext.executeOperation(AbstractOperationContext.java:370)
[0m[31m2016-12-17 13:25:49,140 ERROR [stderr] (ServerService Thread Pool -- 28)     at org.jboss.as.controller.ParallelBootOperationStepHandler$ParallelBootTask.run(ParallelBootOperationStepHandler.java:359)
[0m[31m2016-12-17 13:25:49,140 ERROR [stderr] (ServerService Thread Pool -- 28)     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
[0m[31m2016-12-17 13:25:49,140 ERROR [stderr] (ServerService Thread Pool -- 28)     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
[0m[31m2016-12-17 13:25:49,140 ERROR [stderr] (ServerService Thread Pool -- 28)     at java.lang.Thread.run(Thread.java:745)
[0m[31m2016-12-17 13:25:49,140 ERROR [stderr] (ServerService Thread Pool -- 28)     at org.jboss.threads.JBossThread.run(JBossThread.java:320)
[0m[31m2016-12-17 13:25:49,141 ERROR [stderr] (ServerService Thread Pool -- 28) Caused by: org.jboss.modules.xml.XmlPullParserException: Failed to resolve artifact 'my.repo.group.id:ojdbc6:11.2.0.1.0' (position: END_TAG seen ... name="my.repo.group.id:ojdbc6:11.2.0.1.0"/>... @6:81) 
[0m[31m2016-12-17 13:25:49,141 ERROR [stderr] (ServerService Thread Pool -- 28)     at org.jboss.modules.xml.ModuleXmlParser.parseArtifact(ModuleXmlParser.java:838)
[0m[31m2016-12-17 13:25:49,141 ERROR [stderr] (ServerService Thread Pool -- 28)     at org.jboss.modules.xml.ModuleXmlParser.parseResources(ModuleXmlParser.java:739)
[0m[31m2016-12-17 13:25:49,141 ERROR [stderr] (ServerService Thread Pool -- 28)     at org.jboss.modules.xml.ModuleXmlParser.parseModuleContents(ModuleXmlParser.java:535)
[0m[31m2016-12-17 13:25:49,141 ERROR [stderr] (ServerService Thread Pool -- 28)     at org.jboss.modules.xml.ModuleXmlParser.parseDocument(ModuleXmlParser.java:340)
[0m[31m2016-12-17 13:25:49,141 ERROR [stderr] (ServerService Thread Pool -- 28)     at org.jboss.modules.xml.ModuleXmlParser.parseModuleXml(ModuleXmlParser.java:226)
[0m[31m2016-12-17 13:25:49,141 ERROR [stderr] (ServerService Thread Pool -- 28)     ... 16 more

I've been able to confirm that the example code works from the wildfly-swarm project, so I'm confident that I don't have a networking, configuration, or obvious maven dependency issue in my project; I can get this to work fine with the mysql driver for example, it installs with no apparent issue. I'm also confident that I don't have an issue with accessing my private maven repo - settings.xml and security-settings.xml are configured correctly for this and other projects and this driver artifact is correctly installed in my local repository.

Any insight would be appreciated - I think I'm either missing something really dumb or I'm trying to do something unsupported. Interestingly if I manually copy the resource node from my local maven repo into what appears to me to be a temp project build repo (the path is odd, it's <project root>/? ~/repository?/.m2 and yes, the path includes question marks, whitespace, and tildes) the deployment works.

2

There are 2 answers

0
rekgm_chan On BEST ANSWER

So it turns out I was trying to do something dumb and unsupported.

My settings.xml local repository config looked like this (I'm on OSX 10.12):

<localRepository>
    /Users/rekgm/.m2/repository
</localRepository>

MavenSettings.java doesn't strip out the whitespace, so the MavenResolver that the WF Swarm bootstrap module uses couldn't properly figure out where the local maven repo lives so it would try and redownload the artifact from a remote maven repo. This works great for artifacts that live in unsecured remote repos, but MavenArtifactUtil.downloadFile() doesn't understand that a remote repo could be secured. Hence the error I was getting.

I changed my settings.xml file to this:

<localRepository>/Users/rekgm/.m2/repository</localRepository>

and added the Oracle dependency to the main project pom.xml:

<dependencies>
    ...
    <dependency>
        <groupId>my.repo.group.id</groupId>
        <artifactId>ojdbc6</artifactId>
        <version>11.2.0.1.0</version>
    </dependency>
    ...
</dependencies>

and this clears up the error. I'll probably submit a bug and a feature request at some point.

1
Ken On

I think it's a problem in that the security settings for Maven are not being used for retrieving the artifact, which is why it can't be found.

Having said that, since 2016.12.0 there's an even easier way to configure a JDBC driver without writing a module.xml. Take a look at https://howto.wildfly-swarm.io/create-a-datasource/, it explains how to just add the Maven dependency of the JDBC driver and then configure it with yml