Hi,
On 5 janv. 2014, at 20:07, Hermann Matthes <[email protected]> wrote:
> Hello everybody,
> I try to learn ipojo to implement a simple server using Netbeans 7.4 and
> Apache Karaf.
>
> My first goal is to write a really simple server which just prints a message
> when it's activated or deactivated. No tutorial which I found gave enough
> information to perform such a simple task.
>
> Here's my code:
>
> The server interface:
>
> package de.hermannmatthes.workbench.server;
> public interface Server {
> public void start();
> public void stop();
> }
>
> The server implementation:
>
> package de.hermannmatthes.workbench.server;
>
> import java.io.FileWriter;
> import java.io.IOException;
> import java.util.logging.Level;
> import java.util.logging.Logger;
> import org.apache.felix.ipojo.annotations.Component;
> import org.apache.felix.ipojo.annotations.Instantiate;
> import org.apache.felix.ipojo.annotations.Invalidate;
> import org.apache.felix.ipojo.annotations.Requires;
> import org.apache.felix.ipojo.annotations.Validate;
> import org.osgi.service.log.LogService;
>
> @Component(immediate=true)
> @Instantiate
> public class ServerImpl implements Server {
>
> @Requires(policy="static")
> private LogService log;
>
> @Override
> @Validate
> public void start() {
> trace("Starting workbench server, log is " + log);
> log.log(LogService.LOG_INFO, "Starting workbench server.");
> }
>
> @Override
> @Invalidate
> public void stop() {
> trace("Stopping workbench server, log is " + log);
> log.log(LogService.LOG_INFO, "Stopping workbench server.");
> }
>
> private void trace(final String msg) {
> FileWriter w = null;
> try {
> w = new FileWriter("C:/temp/test.log", true);
> w.write(msg + "\n");
> } catch (IOException ex) {
> Logger.getLogger(ServerImpl.class.getName()).log(Level.SEVERE,
> null, ex);
> }
> finally {
> if (w!=null) {
> try {
> w.close();
> } catch (IOException ex) {
>
> Logger.getLogger(ServerImpl.class.getName()).log(Level.SEVERE, null, ex);
> }
> }
> }
> }
> }
>
> If I install the module in karaf and resolve it, everything's fine. But when
> I start it, its state changes to Active but nothing happens. In the
> attachment you find my project file.
>
> Can someone tell me whats wrong with my code?
Is the log service available ? Try to set it ‘optional’ (optional=true).
Regards,
Clement
>
> Any hint is welcome
> Hermann
> <pom.xml>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]