掲示板

OSGI Sqlserver dependency

thumbnail
6年前 に Gustavo Oliveira によって更新されました。

OSGI Sqlserver dependency

Junior Member 投稿: 98 参加年月日: 15/09/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
6年前 に David H Nebinger によって更新されました。

RE: OSGI Sqlserver dependency

Liferay Legend 投稿: 14916 参加年月日: 06/09/02 最新の投稿
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
6年前 に Gustavo Oliveira によって更新されました。

RE: OSGI Sqlserver dependency

Junior Member 投稿: 98 参加年月日: 15/09/23 最新の投稿
Ok, I will try it.

Thanks
thumbnail
6年前 に Gustavo Oliveira によって更新されました。

RE: OSGI Sqlserver dependency

Junior Member 投稿: 98 参加年月日: 15/09/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
6年前 に David H Nebinger によって更新されました。

RE: OSGI Sqlserver dependency

Liferay Legend 投稿: 14916 参加年月日: 06/09/02 最新の投稿
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
4年前 に Nader Jafari によって更新されました。

RE: OSGI Sqlserver dependency

Junior Member 投稿: 84 参加年月日: 11/08/24 最新の投稿
Hi David
for using JNDI to conect MSQL i should add all dependencies to global library finally as i understand.
thumbnail
4年前 に Nader Jafari によって更新されました。

RE: OSGI Sqlserver dependency

Junior Member 投稿: 84 参加年月日: 11/08/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'
}