留言板

OSGI Sqlserver dependency

thumbnail
Gustavo Oliveira,修改在6 年前。

OSGI Sqlserver dependency

Junior Member 帖子: 98 加入日期: 15-9-23 最近的帖子
Im trying to use SQLServer JDBC driver as a dependency.

Trying to use the latest version: mssql-jdbc-6.2.2.jre8.jar

1. Didnt work putting it on lib/ext.
2. Before adding a lib I run mvn dependency:tree to check all the libs I will have to declare in the bnd. This version doesnt have compile dependencies.

pom.xml:

		<dependency>
			<groupid>com.microsoft.sqlserver</groupid>
			<artifactid>mssql-jdbc</artifactid>
			<version>6.2.2.jre8</version>
		</dependency>		


bnd.bnd:

-includeresource:\
      lib/mssql-jdbc-6.2.2.jre8.jar=mssql-jdbc-6.2.2.jre8.jar;
      
Bundle-ClassPath: \
      .,\
    lib/mssql-jdbc-6.2.2.jre8.jar


I get this error when trying to start it:
Unresolved requirement: Import-Package: com.microsoft.aad.adal4j

Tried using Import-Package: !com.microsoft.aad.adal4j.* I tought I just needed to declare compiling dependencies. Are you guys adding all libs that keeps showing when trying to start? Every time that you need to add one lib you waste several hours trying to figure it out? Im asking it because I stopped using Liferay for a while after the dpx launch, now I will try it again.

Anyone have an example of a portlet with a sqlserver driver?
thumbnail
David H Nebinger,修改在6 年前。

RE: OSGI Sqlserver dependency

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
Gustavo Oliveira:
Anyone have an example of a portlet with a sqlserver driver?


Just don't do it.

Leave the SQL server driver where it is and define a JNDI datasource to the target database.

Inside of your module, you just need to get the JNDI DataSource and can start leveraging it.

No bleed of the driver, the classes, the dependencies, ...
thumbnail
Gustavo Oliveira,修改在6 年前。

RE: OSGI Sqlserver dependency

Junior Member 帖子: 98 加入日期: 15-9-23 最近的帖子
Ok, I will try it.

Thanks
thumbnail
Gustavo Oliveira,修改在6 年前。

RE: OSGI Sqlserver dependency

Junior Member 帖子: 98 加入日期: 15-9-23 最近的帖子
First I tested it with Tomcat and it worked but when I tried in Liferay I got the same error from this Thread:

https://web.liferay.com/pt/community/forums/-/message_boards/message/91115699

"Cannot instantiate class: org.apache.naming.java.javaURLContextFactory"

I tried both approches:

Context context = new InitialContext() and DataSourceFactoryUtil.initDataSource(properties);

I wonder how ppl is doing when they have to connect to another database. External web services? Use Liferay just as a client?
thumbnail
David H Nebinger,修改在6 年前。

RE: OSGI Sqlserver dependency

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
Gustavo Oliveira:
I wonder how ppl is doing when they have to connect to another database.


By reading the documentation...

https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/connecting-to-data-sources-using-jndi
thumbnail
Nader Jafari,修改在4 年前。

RE: OSGI Sqlserver dependency

Junior Member 帖子: 84 加入日期: 11-8-24 最近的帖子
Hi David
for using JNDI to conect MSQL i should add all dependencies to global library finally as i understand.
thumbnail
Nader Jafari,修改在4 年前。

RE: OSGI Sqlserver dependency

Junior Member 帖子: 84 加入日期: 11-8-24 最近的帖子
Hi
I resolved this issue by this changes :
In bnd.bnd  (Finding all !packages was very very painful ...  I hate OSGI when i have to use third party libraries)

-includeresource:\
&nbsp;&nbsp; @mssql-jdbc-7.4.0.jre8.jar,@adal4j-1.6.4.jar,@client-runtime-1.6.15.jar,@azure-keyvault-1.2.2.jar,@okhttp-3.11.0.jar,\
&nbsp;&nbsp; @okio-1.14.0.jar
Import-Package:\
!afu.org.checkerframework.*,\
!com.google.gson.*,\
!com.fasterxml.jackson.datatype.joda.*,\
!com.google.common.*,\
!com.microsoft.azure.*,\
!com.nimbusds.*,\
!net.jcip.*,\
!android.*,\
!rx.*,\
!retrofit2.*,\
!net.minidev.*,\
!org.antlr.*,\
!org.apache.*,\
!org.conscrypt.*,\
!org.joda.time.*,\
!org.osgi.service.jdbc.*,\
*

and in Build.gradle

dependencies {
&nbsp;&nbsp; &nbsp;compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel"
&nbsp;&nbsp; &nbsp;compileOnly group: "com.liferay.portal", name: "com.liferay.util.taglib"
&nbsp;&nbsp; &nbsp;compileOnly group: "javax.portlet", name: "portlet-api"
&nbsp;&nbsp; &nbsp;compileOnly group: "javax.servlet", name: "javax.servlet-api"
&nbsp;&nbsp; &nbsp;compileOnly group: "jstl", name: "jstl"
&nbsp;&nbsp; &nbsp;compileOnly group: "org.osgi", name: "org.osgi.service.component.annotations"
&nbsp;&nbsp; &nbsp;compileOnly group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: '7.4.0.jre8'
&nbsp;&nbsp; &nbsp;compileOnly group: 'com.microsoft.azure', name: 'adal4j', version: '1.6.4'
&nbsp;&nbsp; &nbsp;compileOnly group: 'com.microsoft.azure', name: 'azure-keyvault', version: '1.2.2'
&nbsp;&nbsp; &nbsp;compileOnly group: 'com.microsoft.rest', name: 'client-runtime', version: '1.6.15'
&nbsp;&nbsp; &nbsp;compileOnly group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.11.0'
&nbsp;&nbsp; &nbsp;compileOnly group: 'com.squareup.okio', name: 'okio', version: '1.14.0'
}