Wenn ihr Apache Felix nutzt und die telnet Shell aktiviert habt
osgi.shell.telnet.port=6666
Könnt ihr mit folgendem Skript einfach eure Bundles aktualisieren.
#!/usr/bin/perl
use strict;
use warnings;
use Net::Telnet;
if (@ARGV != 2) {
print "$0: [bundle name substring] [bundle jar absolute path]\n";
exit 1;
}
my $bname = shift;
my $bfile = shift;
my $host = 'localhost';
my $port = 6666;
sub get_bundle_id($$) {
my ($procs, $bname) = @_;
my @proc = grep { m/$bname/i } @$procs;
die "No bundle $bname found." unless @proc > 0;
warn "Multiple bundles $bname found." if @proc > 1;
$proc[0] =~ m/^\[\s*(\d+)\s*\]/;
return $1;
}
my $prompt = '/->/';
my $telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die', Prompt => $prompt);
$telnet->open(Host => $host, Port => $port);
$telnet->waitfor($prompt);
my @procs = $telnet->cmd('ps');
my $bid = get_bundle_id(\@procs, $bname);
print "Bundle id for $bname is $bid\n";
print "Updating bundle $bid with $bfile\n";
my @result = $telnet->cmd("update $bid file:$bfile");
print "Error: ", $result[0], "\n" if (@result > 0 && $result[0] =~ m/unable|error|fail/i);
print "done.\n";
Dies kann auch einfach in Maven integriert werden, dazu muss einfach sicher gestellt werden, dass das Skript im PATH vorhanden oder der Absolute Pfad angeben wird:
<!-- Directly deploy to osgi -->
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<version>1.1</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>osgi_deploy.pl</executable>
<arguments>
<argument>${project.name}</argument>
<argument>${project.build.directory}/${project.build.finalName}.jar</argument>
</arguments>
</configuration>
</plugin>
Die Ausführung:
$ mvn exec:exec
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building MyProject
[INFO] task-segment: [exec:exec]
[INFO] ------------------------------------------------------------------------
[INFO] [exec:exec {execution: default-cli}]
[INFO] Bundle id for MyProject is 5
[INFO] Updating bundle 5 with /home/bpeter/workspaces/MyProject/trunk/myproject/target/myproject.jar
[INFO] done.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
hf