Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using mssql-jdbc cause project build problems #429

Closed
Anjytka opened this issue Aug 2, 2017 · 15 comments
Closed

Using mssql-jdbc cause project build problems #429

Anjytka opened this issue Aug 2, 2017 · 15 comments
Assignees

Comments

@Anjytka
Copy link

Anjytka commented Aug 2, 2017

Driver version or jar name

6.2.1.jre8

SQL Server version

13.0.4001.0

Client operating system

Windows 7

Java/JVM version

Example: java version "1.8.0_131", Java HotSpot(TM) 64-Bit Server VM

Problem description

3 problems occured when dependency mssql-jdbc was added.

Expected behavior and actual behavior

Expected:
Including dependency mssql-jdbc cause no promlem.

Actual:
I work on project that require connection to MS SQL Server. Main part of project is Bamboo plugin for bamboo 5.13.2 version, which use OSGI. When I have added mssql-jdbc dependency to my lib, which was used in main project, I've faced problems.

First of all, I have had to add two dependencies to lib, cos they haven't been recieved transitively.
Error (the same one occured for azure-keyvault):
2017-08-02 10:22:28,452 ERROR [localhost-startStop-1] [OsgiPlugin] Detected an error (BundleException) enabling the plugin 'blabla.plugin.name' : Unresolved constraint in bundle blabla.plugin.name [19]: Unable to resolve 19.0: missing requirement [19.0] osgi.wiring.package; (osgi.wiring.package=com.microsoft.aad.adal4j).
Solution:

    <dependency>
        <groupId>com.microsoft.azure</groupId>
        <artifactId>azure-keyvault</artifactId>
        <version>0.9.7</version>
    </dependency>

    <dependency>
        <groupId>com.microsoft.azure</groupId>
        <artifactId>adal4j</artifactId>
        <version>1.1.3</version>
    </dependency>

Moreover, I have had to exclude packets below at OSGI config section :
Error (the same one for others):
2017-08-02 10:36:24,750 ERROR [localhost-startStop-1] [OsgiPlugin] Detected an error (BundleException) enabling the plugin 'blabla.plugin.name' : Unresolved constraint in bundle blabla.plugin.name [19]: Unable to resolve 19.0: missing requirement [19.0] osgi.wiring.package; (osgi.wiring.package=org.apache.avalon.framework.logger).
Solution:

	!org.apache.avalon.framework.*,
	!com.sun.xml.*,
	!org.jvnet.*,
	!sun.security.util,
	!android.*,
	!org.cryptomator.siv,
	!org.joda.convert,
	!org.opensaml.*,
	!sun.misc,
	!org.eclipse.persistence.*,

Furthermore error with dependencies correlation have occured. I've resolved it using section in dependency azure-keyvault, which have been added as a solution of first error.
Error:
[INFO] [talledLocalContainer] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'activator' defined in URL [bundle://93.0:0/META-INF/spring/atlassian-plugins-components.xml]: Invocation of init method failed; nested exception is com.sun.jersey.spi.service.ServiceConfigurationError: com.sun.jersey.spi.HeaderDelegateProvider: The class com.sun.jersey.core.impl.provider.header.LocaleProvider implementing provider interface com.sun.jersey.spi.HeaderDelegateProvider could not be instantiated: Cannot cast com.sun.jersey.core.impl.provider.header.LocaleProvider to com.sun.jersey.spi.HeaderDelegateProvider
Solution:

	<dependency>
	    <groupId>com.microsoft.azure</groupId>
	    <artifactId>azure-keyvault</artifactId>
	    <version>0.9.7</version>
	    <exclusions>
	        <exclusion>
	            <artifactId>jersey-client</artifactId>
	            <groupId>com.sun.jersey</groupId>
	        </exclusion>
	        <exclusion>
	            <artifactId>jersey-json</artifactId>
	            <groupId>com.sun.jersey</groupId>
	        </exclusion>
	    </exclusions>
	</dependency>

I'm thinking where are too much exclusions and I'm fearing it can lead to more problems later. Is there clearer way to resolve that three errors?

@xiangyushawn
Copy link
Contributor

Hello @Anjytka Thank you for creating the issue and providing such detailed information.

It looks like the root cause is that azure-keyvault and adal4j are not OSGI supported. refer to this issue. Let me keep investigating and I will keep you updated. Thank you.

@xiangyushawn xiangyushawn self-assigned this Aug 2, 2017
@xiangyushawn
Copy link
Contributor

Hello @Anjytka , from my investigation, I am not able to reproduce the same error with OSGI framework... it works on my OSGI test code. Can I ask you a few more questions to narrow down my investigation?

How do you add the driver as dependency? For example, via maven ?

How do you use the driver in your code? Do you use any particular feature of the driver ?

Also want to confirm with you, you are using version 6.2.1, right?

@Anjytka
Copy link
Author

Anjytka commented Aug 4, 2017

Hello @v-xiangs
There is the dependency adding via maven:

        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <version>6.2.1.jre8</version>
        </dependency>

There is the code, which interact with driver:

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connectionUrl = "jdbc:sqlserver://localhost;instanceName=SQLEXPRESS;integratedSecurity=true;";
    try {
        Connection con = DriverManager.getConnection(connectionUrl);
        String SQL = "select name from sys.databases";
        Statement stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery(SQL);
        while (rs.next()) {
            System.out.println(rs.getString(1));
        }
        rs.close();
        stmt.close();
        con.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }

And maybe it'll help you to reproduce the issue, there are bamboo dependensies' specifications below:

    <properties>
        <bamboo.version>5.13.2</bamboo.version>
        <bamboo.data.version>5.13.2</bamboo.data.version>
        <amps.version>6.2.11</amps.version>
        <plugin.testrunner.version>1.2.3</plugin.testrunner.version>
        <atlassian.spring.scanner.version>1.2.13</atlassian.spring.scanner.version>
    </properties>

Hope my answer will be helpfull.

@xiangyushawn
Copy link
Contributor

Thanks for the details! @Anjytka the information you provided is very useful ! Give me some time and I will get back to you. Thank you!

@xiangyushawn
Copy link
Contributor

xiangyushawn commented Aug 4, 2017

Hello @Anjytka from my investigation, if we look at the MANIFEST.MF in the driver, we can see the 2 dependencies, adal4j and azure.keyvault are listed as resolution:=optional, so those 2 dependencies are expected to not received transitively. But I dont understand why your OSGI framework requires those 2 optional dependencies and gives you error if you don't include them explicitly...

Is it possible the OSGI framework on bamboo does not support keyword resolution:=optional?

Also, could you please try one thing?

<dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <version>6.2.1.jre8</version>
	    <optional>true</optional>
</dependency>

I want to see if adding the driver as optional dependency will make a difference or not.

Thank you very much for trying this for us!

@Anjytka
Copy link
Author

Anjytka commented Aug 7, 2017

Hello @v-xiangs. I tried to add <optional>true</optional> to <artifactId>mssql-jdbc</artifactId>.
It allows me to delete adal4j and azure.keyvault dependencies that I need to add to resolve first error. But I have to leave exclusions in OSGI <Import-Package> configuration section, is it ok? Otherwise plugin fails with same second error:

Error (the same one for others):
2017-08-02 10:36:24,750 ERROR [localhost-startStop-1] [OsgiPlugin] Detected an error (BundleException) enabling the plugin 'blabla.plugin.name' : Unresolved constraint in bundle blabla.plugin.name [19]: Unable to resolve 19.0: missing requirement [19.0] osgi.wiring.package; (osgi.wiring.package=org.apache.avalon.framework.logger).

	!org.apache.avalon.framework.*,
	!com.sun.xml.*,
	!org.jvnet.*,
	!sun.security.util,
	!android.*,
	!org.cryptomator.siv,
	!org.joda.convert,
	!org.opensaml.*,
	!sun.misc,
	!org.eclipse.persistence.*,

@xiangyushawn
Copy link
Contributor

Hello @Anjytka , thank you very much for testing this for us! I am glad to know adding optional>true</optional> to the dependency definition helps out.

Regarding to your question, when you say "leave exclusions in OSGI <Import-Package> configuration section", do you mean the driver is listed as resolution:=optional in the <Import-Package> section, or you mean the driver is totally removed from the <Import-Package> section? It would be easier for me to answer your question if you could provide what the <Import-Package> section looks like now. Thank you very much for clarification.

@xiangyushawn
Copy link
Contributor

Hello @Anjytka please let us know if there is anything else we can help you with. Otherwise we will close this issue soon :)

@Anjytka
Copy link
Author

Anjytka commented Aug 15, 2017

Hello @v-xiangs Sorry for delaying with the answer. In both situations:

the driver is listed as resolution:=optional in the <Import-Package> section

<Import-Package>
    org.springframework.osgi.*;resolution:="optional",
    org.eclipse.gemini.blueprint.*;resolution:="optional",
    com.microsoft.sqlserver.*;resolution:="optional",
    !org.apache.avalon.framework.*,
    !com.sun.xml.*,
    !org.jvnet.*,
    !sun.security.util,
    !android.*,
    !org.cryptomator.siv,
    !org.joda.convert,
    !org.opensaml.*,
    !sun.misc,
    !org.eclipse.persistence.*,
    *
</Import-Package>

and

the driver is totally removed from the <Import-Package> section

<Import-Package>
    org.springframework.osgi.*;resolution:="optional",
    org.eclipse.gemini.blueprint.*;resolution:="optional",
    !org.apache.avalon.framework.*,
    !com.sun.xml.*,
    !org.jvnet.*,
    !sun.security.util,
    !android.*,
    !org.cryptomator.siv,
    !org.joda.convert,
    !org.opensaml.*,
    !sun.misc,
    !org.eclipse.persistence.*,
    *
</Import-Package>

I have to keep exclusions. In other way installation of my plugin on Bamboo fails.
I use second option in project in life.

@xiangyushawn
Copy link
Contributor

Hello @Anjytka thank you for getting back to us. It looks like those packages are required by other projects, I dont think they are related to the driver. For example, org.eclipse.persistence.* could be introduced by org.eclipse.gemini.blueprint.*

@Anjytka
Copy link
Author

Anjytka commented Aug 16, 2017

I'm not sure about an origin of the dependencies. The only one thing I know, that I need to exclude them after mssql-jdbc dependency adding. I'll research it when I'll have more time. Anyway, @v-xiangs, thanks for help!

@xiangyushawn
Copy link
Contributor

@Anjytka Thank you for explaining it to us. We very appreciate your time and helps. I am glad to know there is at least one solution for you to make it work. I am closing this issue for now. Please free feel to re-open it. Thank you.

@gopibalagala
Copy link

gopibalagala commented Nov 7, 2019

Hi Team,

       I am facing the similar issue with fuse-karaf-7.4.0.fuse-740028-redhat-00001 & mssql-jdbc-7.0.0.jre8

Can you please help me know what is the solution to fix this issue.

WARN | -redhat-00001/deploy | e.j.e.i.JdbcEnvironmentInitiator | 327 - org.jboss.logging.jboss-logging - 3.3.2.Final-redhat-00001 | HHH000342: Could not obtain connection to query metadata : Cannot load JDBC driver class 'com.microsoft.sqlserver.jdbc.SQLServerDriver'

Thanks,
Gopi.

@peterbae
Copy link
Contributor

peterbae commented Nov 7, 2019

The driver is not in your classpath. I'd google this online to find a solution for this.

@gopibalagala
Copy link

gopibalagala commented Nov 9, 2019

Hi Peterbae,

           Thank you for your reply, the driver class jar I have added in my /deploy folder & my pom.xml, But still I am receiving this issue. 

393 | Active | 80 | 1.0.1.RELEASE | EGov-Fuse-Datasource
394 | Active | 80 | 1.0.0.RELEASE | EGov-Interop-Util
395 | Active | 80 | 7.0.0 | Microsoft JDBC Driver for SQL Server
karaf@root()>
karaf@root()>
karaf@root()> bundle:headers 395

Microsoft JDBC Driver for SQL Server (395)

Bnd-LastModified = 1533057440087
Build-Jdk = 10.0.1
Built-By = BLD-003-W81-64$
Created-By = Apache Maven Bundle Plugin
Manifest-Version = 1.0
Tool = Bnd-3.5.0.201709291849

Bundle-Description = Microsoft JDBC Driver for SQL Server.
Bundle-License = http://www.opensource.org/licenses/mit-license.php
Bundle-ManifestVersion = 2
Bundle-Name = Microsoft JDBC Driver for SQL Server
Bundle-SymbolicName = com.microsoft.sqlserver.mssql-jdbc
Bundle-Vendor = Microsoft Corporation
Bundle-Version = 7.0.0

Require-Capability =
osgi.ee;filter:=(&(osgi.ee=JavaSE)(version=1.8))

Export-Package =
com.microsoft.sqlserver.jdbc;
uses:="javax.naming,
javax.naming.spi,
javax.security.auth.callback,
javax.security.auth.login,
javax.sql,
javax.transaction.xa,
microsoft.sql,
org.ietf.jgss";
version=7.0.0,
microsoft.sql;version=7.0.0
Import-Package =
com.microsoft.aad.adal4j;resolution:=optional,
com.microsoft.azure;resolution:=optional,
com.microsoft.azure.keyvault;resolution:=optional,
com.microsoft.azure.keyvault.authentication;resolution:=optional,
com.microsoft.azure.keyvault.models;resolution:=optional,
com.microsoft.azure.keyvault.webkey;resolution:=optional,
com.microsoft.azure.serializer;resolution:=optional,
com.microsoft.rest;resolution:=optional,
com.microsoft.rest.credentials;resolution:=optional,
com.microsoft.rest.protocol;resolution:=optional,
javax.crypto,
javax.crypto.spec,
javax.naming,
javax.naming.directory,
javax.naming.spi,
javax.net.ssl,
javax.security.auth,
javax.security.auth.callback,
javax.security.auth.kerberos,
javax.security.auth.login,
javax.security.auth.x500,
javax.sql,
javax.transaction.xa,
javax.xml.parsers,
javax.xml.stream,
javax.xml.transform,
javax.xml.transform.dom,
javax.xml.transform.sax,
javax.xml.transform.stax,
javax.xml.transform.stream,
okhttp3;resolution:=optional,
org.ietf.jgss,
org.w3c.dom,
org.xml.sax,
retrofit2;resolution:=optional

karaf@root()>

--
Below the Pom.xml what I have added the depency and import packg.

I have added the mssql-jdbc-7.0.0.jre8 & import packg added this (com.microsoft.sqlserver.jdbc,*)

com.microsoft.sqlservermssql-jdbc 7.0.0.jre8

com.microsoft.sqlserver.jdbc, *

2019-11-09 12:14:55,074 | WARN | -redhat-00001/deploy | e.j.e.i.JdbcEnvironmentInitiator | 261 - org.jboss.logging.jboss-logging - 3.3.2.Final-redhat-00001 | HHH000342: Could not obtain connection to query metadata : Cannot load JDBC driver class 'com.microsoft.sqlserver.jdbc.SQLServerDriver'

Thanks,
Gopi.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants