-1

We are using Wildfly 10 for the first time, upgrading from JBoss EAP 5.1.2. One thing that we need is to have our datasources using the ojdbc6 Oracle driver. I know there are 3 ways to configure them:

1 - Installing the driver and configuring the modules and datasources via configuration files, as shown in this article:

http://www.adam-bien.com/roller/abien/entry/installing_oracle_jdbc_driver_on

2 - Put the ojdbc6.jar in the D:\wildfly-10.1.0.Final\standalone\deployments folder, start the server. Via Wildfly 10 Administration Console, configure the datasource in Configuration -> Subsystems -> Datasources -> Non-XA usint the ojdbc6 driver we put in deployments folder;

3 - Via Wildfly 10 Administration Console, deploy the ojdbc6.jar like any normal deploy in Deployment tab, and them via Wildfly 10 Administration Console, configure the datasource in Configuration -> Subsystems -> Datasources -> Non-XA usint the ojdbc6 driver we just deployed.

Since our customers are used and demand instalations via administration consoles whenever possible, we choose way number 3 to configure the ojdbc6 driver and create our datasources.

Now here's the problem: our application has an environment check that among other things checks the Oracle driver version to make sure we are using the ojdbc6 Oracle driver. This environment check is mandatory for our application to start. Or environment check class has the following code to check the Oracle driver:

/** 
 * @return Caminho do jar do driver Oracle 
 * @see "http://www.javaxt.com/Tutorials/Jar/How_to_Get_the_Physical_Path_of_a_Jar_File" 
 */  
private String getOracleJarPath() {  
  try {  
  // Oracle driver class  
  final Class<?> clazz = oracle.jdbc.OracleDriver.class;  

  final String path = clazz.getPackage().getName().replace(".", "/");  
  String url = clazz.getClassLoader().getResource(path).toString();  

  url = url.replace(" ", "%20"); // Normalize URI  
  url = url.replace(path + "/", ""); // remove package from path  
  final URI uri = new URI(url);  
  return new File(uri.getPath()).getAbsolutePath();  
  } catch (final Exception e) {  
  // Nothing to do  
  }  
  return StringUtils.EMPTY;  
}  

When I deploy our application via Wildfly 10 Administration Console an error happens at line 38 (8 in the above code):

2017-06-21 10:54:49,332 ERROR [br.com.synchro.framework.ambiente.service.impl.ValidadorAmbienteServiceImpl] (default task-2) Erro ao validar ambiente em todos os estágios.: java.lang.NoClassDefFoundError: oracle/jdbc/OracleDriver  
  at br.com.synchro.sfw.infra.ambiente.integration.impl.ValidadorAmbienteVersaoDriverJdbc.getOracleJarPath(ValidadorAmbienteVersaoDriverJdbc.java:38)  
  at br.com.synchro.sfw.infra.ambiente.integration.impl.ValidadorAmbienteVersaoDriverJdbc.validarDriverOracle(ValidadorAmbienteVersaoDriverJdbc.java:149)  
  at br.com.synchro.sfw.infra.ambiente.integration.impl.ValidadorAmbienteVersaoDriverJdbc.validar(ValidadorAmbienteVersaoDriverJdbc.java:106)  
  at br.com.synchro.framework.ambiente.service.impl.ValidadorAmbienteServiceImpl.validarAmbienteSegundoEstagio(ValidadorAmbienteServiceImpl.java:137)  
  at br.com.synchro.framework.ambiente.service.impl.ValidadorAmbienteServiceImpl.validarAmbienteTodosEstagios(ValidadorAmbienteServiceImpl.java:156)  
  at br.com.synchro.framework.gui.presentation.filter.ValidacaoAmbienteFilter.doFilter(ValidacaoAmbienteFilter.java:55)  
  at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)  
  at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)  
  at br.com.synchro.framework.gui.presentation.filter.AplicacaoPatchFilter.doFilter(AplicacaoPatchFilter.java:53)  
  at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)  
  at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)  
  at br.com.synchro.framework.gui.presentation.filter.XUaCompatibleFilter.doFilter(XUaCompatibleFilter.java:28)  
  at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)  
  at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)  
...  

Thus mean, we can't find the driver in our application classpath!

When I created the driver and datasource via method 1, our application works with no problem. But if I use method 2 or 3 the application cannot find the driver in the classpath at all. Since our customers demand instalation exclusively via Administration Console, what can I do or what am I doing wrong that the driver is not in our application classpath?!

Thanks in advance!!!

rsoliveira
  • 21
  • 3

1 Answers1

0

Try something like:

@Startup
@Singleton
public class JDBCDriverVerifier {

    @Resource(name="java:jboss/datasources/YourDS)
    private DataSource ds;

    @PostConstruct
    void checkDriver() {
        try(Connection conn = ds.getConnection()) {

             DatabaseMetaData metaData = conn.getMetaData();
             String driverName = metaData.getDriverName();
             String driverVersion = metaData.getDriverVersion();

             // get other meta data if useful
             // validate and throw exception if it fails...

        }
    }

}

You may need to experiment to see what metadata is the most useful for you.

Note that this will work even if you have a WAR only deployment.

Also, it's worth educating your customers about the value of using JBoss CLI scripts to configure their servers. These scripts can be source controlled (and commented), allowing new environments to be brought up quickly because they make the process repeatable. Console configuration is almost never repeatable. Most of the major Java EE server implementations have this capability in one form or another.

Steve C
  • 18,876
  • 5
  • 34
  • 37
  • The problem is that when I check the driver version usint the connection metadata I need to tell where the jar containing the driver is located, that's why I instantiate the class to get the path. If the driver was in the ckasspath it would be found and ClassnotFoundException would not be raised. Also, other servers we support like WebSphere and Weblogic the user do everything via admin console; the only exception was the JBoss EAP that we needed to tell them to configure via scripts and properties file. Why not have them use the admin console on Wildfly? – rsoliveira Jun 21 '17 at 19:57
  • JBoss/WildFly uses a virtual file system, so when you deploy your driver using the admin console (or via CLI, which uses the same mechanism for deployment) you will not find it in the physical file system. Secondly, I explained in my last paragraph why a scripted solution is better. – Steve C Jun 24 '17 at 00:00