users@glassfish.java.net

Re: How to call datasource in OSGI bundle?

From: Sahoo <sanjeeb.sahoo_at_oracle.com>
Date: Tue, 24 Jan 2012 06:06:55 +0530

It's not a compilation failure. Bundle plugin is unable to see
javax.annotation and javax.activation classes while trying to compute
OSGi manifest of your bundle and decide what to package in your jar. You
have to fix your pom.xml. I suggest you use
https://svn.java.net/svn/glassfish~svn/trunk/fighterfish/sample/parent-pom/pom.xml
as parent pom to help you configure things correctly.

I am not sure about use @Resource in SessionHandleImpl. Is it a managed
object or not? You can't use injection in non-managed objects.

Sahoo

On Monday 23 January 2012 07:42 PM, forums_at_java.net wrote:
> Is it possible to call @Datasource insight OSGI bundle? I configured
> Connection pool in the Glassfish 3.1.1 Server. I can make queries from
> simple
> JSF application. This is the source code of the bundles:
> http://www.2shared.com/file/H8kNkMrI/SH_27.html [1]
>
> This is the source code that I'm trying to write:
>
> package org.DX_57.osgi.SH_27.impl;
> import javax.activation.DataSource;
> import javax.annotation.Resource;
> import org.DX_57.osgi.SH_27.api.SessionHandle;
> public class SessionHandleImpl implements SessionHandle {
> public String error_Message = null;
> public String error_Database = null;
> /** Call the Oracle JDBC Connection driver */
> @Resource(name="jdbc/Oracle")
> public DataSource ds;
> public String sayHello(String name) {
> return "Howdy " + name;
> }
> }
> When I try to compile the code with Netbeans this error appears:
>
> [bundle:bundle]
> Bundle org.DX_57.osgi.SH_27:SH_27-impl:bundle:1.0-SNAPSHOT : Unresolved
> references to [javax.activation, javax.annotation] by class(es) on the
> Bundle-Classpath[Jar:dot]:
> [org/DX_57/osgi/SH_27/impl/SessionHandleImpl.class]
> Error(s) found in bundle configuration
> ------------------------------------------------------------------------
> Reactor Summary:
> SH_27 ............................................. SUCCESS [0.639s]
> SH_27-api ......................................... SUCCESS [5.162s]
> SH_27-impl ........................................ FAILURE [1.930s]
> ------------------------------------------------------------------------
> BUILD FAILURE
> ------------------------------------------------------------------------
> Total time: 8.950s
> Finished at: Mon Jan 23 15:59:42 EET 2012
> Final Memory: 18M/47M
> ------------------------------------------------------------------------
> Failed to execute goal org.apache.felix:maven-bundle-plugin:2.3.6:bundle
> (default-bundle) on project SH_27-impl: Error(s) found in bundle
> configuration -> [Help 1]
> Do you have any idea what I'm missing?
>
> Bets wishes
>
>
>
>
> [1] http://www.2shared.com/file/H8kNkMrI/SH_27.html
>
> --
>
> [Message sent by forum member 'rcbandit']
>
> View Post: http://forums.java.net/node/882924
>
>