我正在寻找一种方法来(重新)部署一个爆炸的捆绑包(意思是没有震动,但在文件夹中)从Eclipse内部运行Apache Felix OSGi容器,最好是使用启动任务 .

我找到了this问题,答案很接近,但这取决于在Gogo shell中输入命令,这对于长期开发使用来说不方便 . 我为此启动了任务机制,但如果有同样快速和方便的替代方案,我也对此持开放态度 .

现在我认为如果我可以从Eclipse启动任务中发出Gogo shell命令,那将是一个解决方案,但我也无法理解如何做到这一点 . 我认为我需要Remote Shell捆绑包吗?

我开始考虑用Java编写一个telnet客户端,它可以连接到Remote Shell软件包并以自动方式执行Gogo命令 . 我已经看过some example已经可以根据我的需要进行修改......但是我从中得到了一种感觉'reinventing the wheel' . 当然有更好的方法吗?

一些背景知识可以帮助您了解我在做什么:

我已经设置了一个Eclipse 'OSGiContainer'项目,该项目基本上包含Apache Felix jar和我要部署的第三方软件包(如Gogo shell),类似于here描述的项目设置 . 然后我创建了第二个包含我的包的'MyBundle'项目 . 我想通过启动OSGiContainer项目来启动OSGi容器,然后在我的bundle上开发并通过将MyBundle项目启动到OSGiContainer来测试我的更改,我想在开发过程中保持一直运行 .

项目布局:

OSGiContainer

bin(包含felix jar)

捆绑(第三方捆绑)

conf(Felix'config.properties文件)

MyBundle

src

目标

然后我可以通过在Gogo shell上调用这些命令将我的bundle部署到OSGi容器:

install reference:file:../MyBundle/target/classes

start

要重新部署,我调用这些命令:

stop

uninstall

install reference:file:../MyBundle/target/classes

start

你可以想象每次在shell上调用4个命令都不是那么有趣......所以即使你能给我一个方法来把它归结为更少的命令来输入它也将是一个很大的改进 .

UPDATE

我唠叨了一下,想出了下面的课程 . 它是telnet示例的一个改编版本,带有一些小的更改和一个main方法,带有必要的命令来卸载一个bundle然后重新安装并启动它 . bundle的路径应作为程序的参数给出,如下所示:

reference:file:../MyBundle/target/classes

我仍然非常欢迎这个问题的答案,因为我根本不喜欢这个解决方案 . 但我已经证实这有效:

import java.io.IOException;

import java.io.InputStream;

import java.io.PrintStream;

import java.net.SocketException;

import java.util.concurrent.BlockingQueue;

import java.util.concurrent.CountDownLatch;

import java.util.concurrent.LinkedBlockingQueue;

import org.apache.commons.net.telnet.TelnetClient;

public class GogoDeployer {

static class Responder extends Thread {

private StringBuilder builder = new StringBuilder();

private final GogoDeployer checker;

private CountDownLatch latch;

private String waitFor = null;

private boolean isKeepRunning = true;

Responder(GogoDeployer checker) {

this.checker = checker;

}

boolean foundWaitFor(String waitFor) {

return builder.toString().contains(waitFor);

}

public synchronized String getAndClearBuffer() {

String result = builder.toString();

builder = new StringBuilder();

return result;

}

@Override

public void run() {

while (isKeepRunning) {

String s;

try {

s = checker.messageQueue.take();

} catch (InterruptedException e) {

break;

}

synchronized (Responder.class) {

builder.append(s);

}

if (waitFor != null && latch != null && foundWaitFor(waitFor)) {

latch.countDown();

}

}

System.out.println("Responder stopped.");

}

public String waitFor(String waitFor) {

synchronized (Responder.class) {

if (foundWaitFor(waitFor)) {

return getAndClearBuffer();

}

}

this.waitFor = waitFor;

latch = new CountDownLatch(1);

try {

latch.await();

} catch (InterruptedException e) {

e.printStackTrace();

return null;

}

String result = null;

synchronized (Responder.class) {

result = builder.toString();

builder = new StringBuilder();

}

return result;

}

}

static class TelnetReader extends Thread {

private boolean isKeepRunning = true;

private final GogoDeployer checker;

private final TelnetClient tc;

TelnetReader(GogoDeployer checker, TelnetClient tc) {

this.checker = checker;

this.tc = tc;

}

@Override

public void run() {

InputStream instr = tc.getInputStream();

try {

byte[] buff = new byte[1024];

int ret_read = 0;

do {

if (instr.available() > 0) {

ret_read = instr.read(buff);

}

if (ret_read > 0) {

checker.sendForResponse(new String(buff, 0, ret_read));

ret_read = 0;

}

} while (isKeepRunning && (ret_read >= 0));

} catch (Exception e) {

System.err.println("Exception while reading socket:" + e.getMessage());

}

try {

tc.disconnect();

checker.stop();

System.out.println("Disconnected.");

} catch (Exception e) {

System.err.println("Exception while closing telnet:" + e.getMessage());

}

}

}

private static final String prompt = "g!";

private static GogoDeployer client;

private String host;

private BlockingQueue messageQueue = new LinkedBlockingQueue();

private int port;

private TelnetReader reader;

private Responder responder;

private TelnetClient tc;

public GogoDeployer(String host, int port) {

this.host = host;

this.port = port;

}

public void stop() {

responder.isKeepRunning = false;

reader.isKeepRunning = false;

try {

Thread.sleep(10);

} catch (InterruptedException e) {

}

responder.interrupt();

reader.interrupt();

}

public void send(String command) {

PrintStream ps = new PrintStream(tc.getOutputStream());

ps.println(command);

ps.flush();

}

public void sendForResponse(String s) {

messageQueue.add(s);

}

public void connect() throws SocketException, IOException {

tc = new TelnetClient();

tc.connect(host, port);

reader = new TelnetReader(this, tc);

reader.start();

responder = new Responder(this);

responder.start();

}

public String waitFor(String s) {

return responder.waitFor(s);

}

private static String exec(String cmd) {

String result = "";

System.out.println(cmd);

client.send(cmd);

result = client.waitFor(prompt);

return result;

}

public static void main(String[] args) {

try {

String project = args[0];

client = new GogoDeployer("localhost", 6666);

client.connect();

System.out.println(client.waitFor(prompt));

System.out.println(exec("uninstall " + project));

String result = exec("install " + project);

System.out.println(result);

int start = result.indexOf(":");

int stop = result.indexOf(prompt);

String bundleId = result.substring(start + 1, stop).trim();

System.out.println(exec("start " + bundleId));

client.stop();

} catch (SocketException e) {

System.err.println("Unable to conect to Gogo remote shell: " + e.getMessage());

} catch (IOException e) {

System.err.println("Unable to conect to Gogo remote shell: " + e.getMessage());

}

}

}

java 调用felix_使用Eclipse启动任务将展开的软件包部署到Apache Felix相关推荐

  1. ictclas包 java_ICTCLAS分词系统Java调用接口在Eclipse中的安装

    ICTCLAS分词系统Java调用接口在Eclipse中的安装 实验环境:JDK1.5.Eclipse3.1.XP操作系统 分词系统Java接口解压包:d:\fenci(http://www.nlp. ...

  2. linux下java调用matlab程序,linux_java调用windows_matlab程序

    0 说明 本文为研究java和matlab的混合编程,进行了详细的测试和探索,以解决linux环境下java程序调用matlab程序的一个应用. linux端的环境 :(运行java程序并调用wind ...

  3. eclipse java调用c 代码吗_linux下通过eclipse开发用java调用c程序的方法

    linux下通过eclipse开发用java调用c程序的方法: 1.先建立好java工程并建立java文件如下: public class testso {     static {         ...

  4. oxyen eclipse 启动 报错 se启动提示javaw.exe in your current PATH、No java virtual machine

    eclipse启动提示javaw.exe in your current PATH.No java virtual machine 另外,也可修改eclipse.ini 文件,在最前面加上下面两行内容 ...

  5. Eclipse启动时报错Java was started but returned exit code=13

    Eclipse启动时报错Java was started but returned exit code=13 如图所示 原因是通过第三方更新JRE时,第三方安装的是32位的JRE,与64位的eclip ...

  6. Eclipse中ICTCLAS 2011 的java调用

    http://hi.baidu.com/tanzhangwen/item/ab7c0909699546dddce5b006 本文由twenz整理. 以前ICTCLAS官方网站上并没有官方的java版本 ...

  7. [Eclips 安装] eclipse启动不了,出现“Java was...”如何解决

    Eclipse 是一个开放源代码的.基于Java的可扩展开发平台.就其本身而言,它只是一个框架和一组服务,用于通过插件组件构建开发环境. 当我们安装使用时,会出现eclipse启动不了,出现" ...

  8. Eclipse启动问题:A java runtime Environment(JRE) or java Development的解决办法

    第一种情况:Java环境没有配置好(解决办法-------见上一篇文章) 第二种情况:javaw.exe路径缺失 1:Eclipse需要javaw.exe来启动,程序会先查找path目录,如果没有找到 ...

  9. Eclipse启动报错:org.eclipse.e4.core.di.InjectionException: java.lang.NoClassDefFoundError: javax/annotat

    启动 Eclipse 的时候,出现了下面这个错误 org.eclipse.e4.core.di.InjectionException: java.lang.NoClassDefFoundError: ...

  10. java启动慢,Eclipse启动慢的问题

    Eclipse启动慢的问题 Eclipse启动时先要搜索jvm.dll的位置, 然后还要加载各种UI插件, 所以非常慢 解决方法: 1. 在 eclipse.ini 中指定 jvm.dll 路径: - ...

最新文章

  1. AI造假 vs AI打假 终结“猫鼠游戏”不能只靠技术
  2. android oppo 权限,OPPO Reno可尝鲜Android Q:教程如下
  3. mysql post 中文乱码_mysql/mariaDB中文乱码问题的处理
  4. VMWare下的DOS与宿主机的文件共享
  5. C++实现successive approximation渐进法(附完整源码)
  6. 方法级别权限控制-基本介绍与JSR250注解使用
  7. React中后台管理系统添加广告分类显示不出来
  8. lua# lua5.1.4 源码文件作用一览
  9. java调用oracle存储过程_做一点,记一点 ~ Java调用Oracle存储过程
  10. 如何以nobody用户执行命令?
  11. cp 时间长 linux,为了节省cp命令时间,结果换来了重装linux系统的差事
  12. git 各种撤销操作办法
  13. win7如何设置wifi热点_win7台式机如何设置IP地址为固定的IP地址?
  14. Apache配置虚拟主机后,不能访问localhost的问题
  15. 小米笔记本显示器关闭后无法唤醒曲线解决办法
  16. 苹果谷歌微软薪酬大揭秘,最高320万元!
  17. pascal语言基础(一)
  18. 飞机大战小游戏 C语言(课设任务)
  19. 买电脑常识——电脑性能
  20. 怎么在小程序里开店铺?【小程序开店】

热门文章

  1. bp神经网络及ROC曲线绘制
  2. 哮喘病人小气道上皮细胞 (Asthma) Small airway epithelial cells 培养解决方案
  3. 微信连wifi portal验证
  4. Vlad and Unfinished Business (图论)
  5. 10-Transformation
  6. Java实现 蓝桥杯 算法训练 递归求二项式系数
  7. 阿里云OSS对象存储基础入门
  8. 安卓密码解锁流程简析
  9. matlab+nbiot,基于STM32L4+BC28(全网通) NBIOT开发板原理图教程源码等开源分享
  10. 联想服务器装系统不能加载硬盘,联想电脑重装系统读不出硬盘怎么办