Hello,

I cleaned up the sources a bit and pasted them below. The code for the
master bundle is not very interesting (it shows a gui with a fileopen
button), apart from the method which loads the bundles and the method
which loads felix.  Both are at the bottom of the post.

Hopefully somebody can help us.

Greetings,

Stefan

Activator.java for dynamically loaded bundle:

package nl.prifes.printer.log;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

public class Activator implements BundleActivator{
    private BundleContext m_context = null;

    public void start(BundleContext context) throws Exception {
        System.out.println("Loading log bundle");
        m_context = context;

        final ClassLoader cl = context.getClass().getClassLoader();
        System.out.println(cl);

        Thread thread = new Thread() {
            @Override
            public void run() {
                System.out.println("pre" +
Thread.currentThread().getContextClassLoader());
                Thread.currentThread().setContextClassLoader(cl);

                PrifesPrinterService serv = new PrifesPrinterService();
                System.out.println("cla" +
Thread.currentThread().getContextClassLoader());
                PrifesPrinter pp = serv.getPrifesPrinterPort();
                System.out.println("sendpre");
                System.out.println(pp.sendData(1, 1, "Test"));
            }
        };

        thread.start();
    }

    public void stop(BundleContext context) throws Exception {
        System.out.println("Stopping log bundle");
        m_context = null;
    }
}

pom.xml for dynamically loaded bundle:

<project>
  <modelVersion>4.0.0</modelVersion>
  <packaging>bundle</packaging>
  <name>PRIFES Printer log</name>
  <description>Does something with logs</description>
  <groupId>nl.prifes.printer</groupId>
  <artifactId>printerlogbundle</artifactId>
  <version>1.0.0</version>

  <dependencies>
    <dependency>
      <groupId>org.apache.felix</groupId>
      <artifactId>org.osgi.core</artifactId>
      <version>1.0.0</version>
    </dependency>
    <dependency>
      <groupId>nl.prifes.printer</groupId>
      <artifactId>prifesprinter</artifactId>
      <version>1.0.0</version>
    </dependency>
    <dependency>
          <groupId>com.sun.xml.ws</groupId>
          <artifactId>jaxws-rt</artifactId>
          <version>2.0_03-SNAPSHOT</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <version>1.4.0</version>
        <extensions>true</extensions>
        <configuration>
          <instructions>
            <Private-Package>nl.prifes.printer.log</Private-Package>
            <Bundle-Activator>nl.prifes.printer.log.Activator</Bundle-Activator>
            
<Import-Package>javax.jws,javax.xml.bind,javax.xml.bind.annotation,javax.xml.namespace,javax.xml.ws,nl.prifes.printer.host.service,org.osgi.framework;version="1.3"</Import-Package>
          </instructions>
        </configuration>
      </plugin>
          <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxws-maven-plugin</artifactId>
                <executions>
                        <execution>
                                <goals>
                                        <goal>wsimport</goal>
                                </goals>
                                <configuration>
                                        <wsdlUrls>
                                                
<wsdlUrl>http://localhost:8084/prifesserver/PrifesPrinter?wsdl</wsdlUrl>
                                        </wsdlUrls>
                                        
<packageName>nl.prifes.printer.log</packageName>
                                </configuration>
                        </execution>
                </executions>
      </plugin>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>RELEASE</version>
        <configuration>
          <source>1.5</source>
          <target>1.5</target>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <repositories>
      <repository>
          <id>maven-repository.dev.java.net</id>
          <name>maven</name>
          <url>http://download.java.net/maven/1/</url>
          <layout>legacy</layout>
      </repository>
      <repository>
          <id>maven2-repository.dev.java.net</id>
          <name>maven2</name>
          <url>http://download.java.net/maven/2/</url>
      </repository>
  </repositories>
  <pluginRepositories>
      <pluginRepository>
          <id>maven2-repository.dev.java.net</id>
          <url>http://download.java.net/maven/2/</url>
      </pluginRepository>
  </pluginRepositories>
</project>

Bundle load method:

    private void actionPerformed(java.awt.event.ActionEvent evt) {
        if(evt.getSource()  == openButton){
            JFileChooser fc = new JFileChooser();
            int retVal = fc.showOpenDialog(ServiceList.this);
            if(retVal == JFileChooser.APPROVE_OPTION){
                File file = fc.getSelectedFile();
                final String filePath = file.toURI().toString();
                System.out.println(filePath);

                try {
                    Bundle b = m_act.getContext().installBundle(filePath);
                    System.out.println(b.getHeaders().toString());
                    ServiceItem si = new ServiceItem(m_act, b);
                    addItem(si);
                }
                catch (BundleException ex) {

Logger.getLogger(ServiceList.class.getName()).log(Level.SEVERE, "Boem
while installing service", ex);
                }
            }
        }
    }


Felix load method:

public static void main(String[] argv) throws Exception{
        final File cachedir =
File.createTempFile("felix.example.servicebased", null);
        cachedir.delete();
        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run(){
                deleteFileOrDir(cachedir);
            }
        });

        Map configMap = new StringMap(false);
        configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES,
            "org.osgi.framework; version=1.3.0," +
            "org.osgi.service.packageadmin; version=1.2.0," +
            "org.osgi.service.startlevel; version=1.0.0," +
            "org.osgi.service.url; version=1.0.0," +
            "org.osgi.util.tracker; version=1.3.2," +
            "nl.prifes.printer.host.service; version=1.0.0," +
            "javax.swing," +
            
"javax.jws,javax.xml.bind.annotation,javax.xml.bind,javax.xml.ws,javax.xml.namespace"
            );
        configMap.put(AutoActivator.AUTO_START_PROP + ".1",""
            );
        configMap.put(FelixConstants.LOG_LEVEL_PROP, "1");
        configMap.put(BundleCache.CACHE_PROFILE_DIR_PROP,
cachedir.getAbsolutePath());

        // Create list to hold custom framework activators.
        List list = new ArrayList();
        // Add activator to process auto-start/install properties.
        list.add(new AutoActivator(configMap));
        // Add our own activator.
        list.add(new Activator());

        try{
            // Now create an instance of the framework.
            Felix felix = new Felix(configMap, list);
            felix.start();
        }
        catch (Exception ex){
            System.err.println("Could not create framework: " + ex);
            ex.printStackTrace();
            System.exit(-1);
        }
    }

On 4/10/08, Marcel Offermans <[EMAIL PROTECTED]> wrote:
> Hello Stefan,
>
>  On Apr 9, 2008, at 13:05 , bitrain _ wrote:
>
>
> > We tried setting the classloader in our own thread:
> >
> >       final ClassLoader cl =
> context.getClass().getClassLoader();
> >       Thread thread = new Thread() {
> >           public void run() {
> >
> Thread.currentThread().setContextClassLoader(cl);
> >
> >               PrifesPrinterService serv = new PrifesPrinterService();
> >               PrifesPrinter pp = serv.getPrifesPrinterPort();
> >               System.out.println(pp.sendData(1, 1,
> "Test"));
> >           }
> >       };
> >       thread.start();
> >
> > The context is the bundlecontext from the bundle which contains the
> > classes. We also tried getting the classloader from the master bundle,
> > but they all produce the same runtime modeler error.
> >
>
>  Hard to tell from just your messages what is going on exactly. The best
> advice I can give you is to use the debugger to figure out exactly what's
> going on inside that code. Try and instrument your classloaders if
> necessary.
>
>
>  Greetings, Marcel
>
>
> ---------------------------------------------------------------------
>  To unsubscribe, e-mail:
> [EMAIL PROTECTED]
>  For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to