Mit einem Mavenprojekt will ich mich nach dieser Anleitung...
https://www.javacodegeeks.com/2011/11/osgi-simple-hello-world-with-services.html
in OSGi einarbeiten. Was ich nicht verstehen kann ist, wieso ich Aktivator bzw. Consumer (also die Klassen HelloWorldActivator.java und HelloWorldConsumer.java) nicht mit pom.xml deployen kann. Die pom ist die folgende:
Wenn ich das Deployment mit maven starte, kommt folgender Fehler:
...dabei habe ich das osgi-framework dem Buildpath hinzugefügt, wieso heißt es dann, dass das package org.osgi.framework nicht existiert? Die Projektstruktur habe ich mal im Anhang hinzgefügt.
Hier ist die Klasse HelloWorldActivator:
https://www.javacodegeeks.com/2011/11/osgi-simple-hello-world-with-services.html
in OSGi einarbeiten. Was ich nicht verstehen kann ist, wieso ich Aktivator bzw. Consumer (also die Klassen HelloWorldActivator.java und HelloWorldConsumer.java) nicht mit pom.xml deployen kann. Die pom ist die folgende:
HTML:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>OSGiDmHelloWorldConsumer</groupId>
<artifactId>OSGiDmHelloWorldConsumer</artifactId>
<version>1.0</version>
<packaging>bundle</packaging>
<dependencies>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.osgi.core</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>OSGiDmHelloWorldProvider</groupId>
<artifactId>OSGiDmHelloWorldProvider</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>OSGiDmHelloWorldConsumer</Bundle-SymbolicName>
<Bundle-Activator>com.bw.osgi.consumer.HelloWorldActivator</Bundle-Activator>
<Bundle-Vendor>Baptiste Wicht</Bundle-Vendor>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>
Wenn ich das Deployment mit maven starte, kommt folgender Fehler:
Code:
[INFO] Building OSGiProject 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ OSGiProject ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\andfe\Documents\eclipse-workspace\OSGiProject\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ OSGiProject ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 9 source files to C:\Users\andfe\Documents\eclipse-workspace\OSGiProject\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/andfe/Documents/eclipse-workspace/OSGiProject/src/com/bw/osgi/consumer/HelloWorldActivator.java:[3,26] package org.osgi.framework does not exist
...dabei habe ich das osgi-framework dem Buildpath hinzugefügt, wieso heißt es dann, dass das package org.osgi.framework nicht existiert? Die Projektstruktur habe ich mal im Anhang hinzgefügt.
Hier ist die Klasse HelloWorldActivator:
Java:
package com.bw.osgi.consumer;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import com.bw.osgi.provider.able.HelloWorldService;
public class HelloWorldActivator implements BundleActivator {
private HelloWorldConsumer consumer;
@Override
public void start(BundleContext bundleContext) throws Exception {
ServiceReference reference = bundleContext.getServiceReference(HelloWorldService.class.getName());
consumer = new HelloWorldConsumer((HelloWorldService) bundleContext.getService(reference));
consumer.startTimer();
}
@Override
public void stop(BundleContext bundleContext) throws Exception {
consumer.stopTimer();
}
}