Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » Run Equinox framework in a main method
Run Equinox framework in a main method [message #717818] Mon, 22 August 2011 13:08
Hesam Hosseini is currently offline Hesam HosseiniFriend
Messages: 1
Registered: August 2011
Junior Member
Hi
I wanted to run the equinox framework from a main method.
this part is pretty easy to do. However when I did this, I had a problem that i had no access to the equinox console.
So my question is this:
How can I run the equinox framework from a main class and have access to the console (by access I mean to send commands and receive the results in Java console).

I have tried to access the console via a socket but when I want to read the results I got stuck at the end of the first results that I get (Since the InputStream.read() is blocking).

Anyone could help me?

_________________________________________________________________________
This is my code:
	public static void main(String[] args) {
		FrameworkFactory ff = ServiceLoader.load(FrameworkFactory.class).iterator().next();
		Map<String, String> configMap = new HashMap<String, String>();
		// Turn on the Equinox console on port 6666 (Equinox only)
		configMap.put("osgi.console", "6666");
		Framework fwk = ff.newFramework(configMap);
		try {
			fwk.start();
		} catch (BundleException e) {
			System.err.println("Exc. occured while Starting Framework");
			e.printStackTrace();
		}
		BundleContext context = fwk.getBundleContext();
		List<Bundle> installedBundles = new LinkedList<Bundle>();
		try {
			installedBundles.add(context.installBundle("file:C:\\Users\\Administrator\\Eclipse Workspace\\JAR File\\TestEQ.jar"));
			installedBundles.add(context.installBundle("file:C:\\Users\\Administrator\\Eclipse Workspace\\JAR File\\printerBundle.jar"));
		} catch (BundleException e) {
			e.printStackTrace();
		}
		int i = 0;
		try {
			for (Bundle bundle : installedBundles) {
				i++;
				bundle.start();
			}
		} catch (BundleException e) {
			System.err.println("Exc. occured at level:" + i);
			e.printStackTrace();
		}

		// ______________________Socket Tester___________________________//

		try {
			Socket socket = new Socket(InetAddress.getByName("0.0.0.0"), 6666);
			PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
			BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
			BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
			System.out.println("[INFO] Connection recieved: " + socket.getInetAddress().getHostName());
			while (true) {
				String userInput = "";
				while ((userInput = stdIn.readLine()) != null) {
					out.print(userInput);

					int osgiResponse = -1;
					while ((osgiResponse = in.read()) != -1) {
						System.out.print((char)osgiResponse);
					}
					System.out.println("OUT OF HELL!");
				}

			}
		} catch (UnknownHostException e1) {
			e1.printStackTrace();
		} catch (IOException e1) {
			e1.printStackTrace();
		}

	}
Previous Topic:Drools install problem
Next Topic:Eclipse Helios crashing after my product is plugged into it
Goto Forum:
  


Current Time: Wed Sep 25 01:51:31 GMT 2024

Powered by FUDForum. Page generated in 0.04482 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top