You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@karaf.apache.org by Charles Moulliard <cm...@gmail.com> on 2011/11/26 13:12:43 UTC

How to access resource of a bundle ?

Hi,

I would like to have access to the resource and class defined in a
bundle. This is for an EJB-jar packaged as a bundle. The code looks
like that

        Enumeration<?> e = bundle.findEntries("META-INF", "ejb-jar.xml", false);

        if (e != null) {
            if (e.hasMoreElements()) {
                URL ejbJarUrl = (URL) e.nextElement();

                LOGGER.info("[Deployer] It's an EJB module: " +
ejbJarUrl); // --> It's an EJB module:
bundle://143.4:0/META-INF/ejb-jar.xml

                String location = bundle.getLocation();

                try {
                    File file = new File(new URL(location).getFile());
                    try {
                        DeploymentLoader deploymentLoader = new
DeploymentLoader();
                        AppModule appModule = deploymentLoader.load(file);

but finally the URL created is not correct as it looks under
karaf_home followed by groupId/artifactId/version

-->

karaf@root> org.apache.openejb.config.UnknownModuleTypeException:
Unable to determine module type for jar:
file:/Users/charlesmoulliard/MyApplications/apache-karaf-2.2.4/org.apache.camel.example/camel-ejb/1.0:
Unknown module type:
url=file:/Users/charlesmoulliard/MyApplications/apache-karaf-2.2.4/org.apache.camel.example/camel-ejb/1.0
	at org.apache.openejb.config.DeploymentLoader.load(DeploymentLoader.java:141)
	at org.apache.openejb.core.osgi.impl.Deployer.deploy(Deployer.java:77)

How can I have access to the jar deployed in karaf or in the cache ?

Regards,

Charles Moulliard

Apache Committer

Blog : http://cmoulliard.blogspot.com
Twitter : http://twitter.com/cmoulliard
Linkedin : http://www.linkedin.com/in/charlesmoulliard
Skype: cmoulliard

Re: How to access resource of a bundle ?

Posted by Guillaume Nodet <gn...@gmail.com>.
There's no file to point at, the OSGi standard does not impose how the
jar is stored, and it can be extracted (some inner jars are somtimes
extracted), so you'd even have multiple jars to point to.
You need to change the OpenEJB discovery mechanism to be more OSGi
friendly.  I'm not sure what resources the OpenEJB deployer looks for,
but you need to rewrite it.

On Sat, Nov 26, 2011 at 13:12, Charles Moulliard <cm...@gmail.com> wrote:
> Hi,
>
> I would like to have access to the resource and class defined in a
> bundle. This is for an EJB-jar packaged as a bundle. The code looks
> like that
>
>        Enumeration<?> e = bundle.findEntries("META-INF", "ejb-jar.xml", false);
>
>        if (e != null) {
>            if (e.hasMoreElements()) {
>                URL ejbJarUrl = (URL) e.nextElement();
>
>                LOGGER.info("[Deployer] It's an EJB module: " +
> ejbJarUrl); // --> It's an EJB module:
> bundle://143.4:0/META-INF/ejb-jar.xml
>
>                String location = bundle.getLocation();
>
>                try {
>                    File file = new File(new URL(location).getFile());
>                    try {
>                        DeploymentLoader deploymentLoader = new
> DeploymentLoader();
>                        AppModule appModule = deploymentLoader.load(file);
>
> but finally the URL created is not correct as it looks under
> karaf_home followed by groupId/artifactId/version
>
> -->
>
> karaf@root> org.apache.openejb.config.UnknownModuleTypeException:
> Unable to determine module type for jar:
> file:/Users/charlesmoulliard/MyApplications/apache-karaf-2.2.4/org.apache.camel.example/camel-ejb/1.0:
> Unknown module type:
> url=file:/Users/charlesmoulliard/MyApplications/apache-karaf-2.2.4/org.apache.camel.example/camel-ejb/1.0
>        at org.apache.openejb.config.DeploymentLoader.load(DeploymentLoader.java:141)
>        at org.apache.openejb.core.osgi.impl.Deployer.deploy(Deployer.java:77)
>
> How can I have access to the jar deployed in karaf or in the cache ?
>
> Regards,
>
> Charles Moulliard
>
> Apache Committer
>
> Blog : http://cmoulliard.blogspot.com
> Twitter : http://twitter.com/cmoulliard
> Linkedin : http://www.linkedin.com/in/charlesmoulliard
> Skype: cmoulliard
>



-- 
------------------------
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/
------------------------
Open Source SOA
http://fusesource.com