Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [equinox-dev] Integrating plugin bundles in normal Java

Hi experts,

Thanks Andrew. adding a -noExit equivalent to my argument prevents my system doing an automatic System.exit(0) on its own. Thus my POJO main method running:
org.eclipse.core.launcher.Main.main(launcherArgs);
can have control after my App A has been run.

However, now my problem is how to return an result object from my App A. org.eclipse.core.launcher.Main.main(launcherArgs) and org.eclipse.equinox.launcher.Main.main(launcherArgs) does not have return type. If my app A which implements org.eclipse.core.runtime.IPlatformRunnable does return an result object in its public Object run(args) method, how do I retrieve it?

I tried cutting over to use EclipseStarter:
      BundleContext context = EclipseStarter.startup(launcherArgs, null);
       Object appResult = EclipseStarter.run(null);


However, I think I am not able to use the same configuration parameters as before:
!ENTRY org.eclipse.osgi 4 0 2009-01-09 16:02:58.719
!MESSAGE Bundle org.eclipse.core.runtime@start not found.

!ENTRY org.eclipse.update.configurator 2009-01-09 16:02:58.859
!MESSAGE C:\pathTo\plugins is not a valid plugins directory.


Any idea?

Regards,
Tom


Andrew Niefer wrote:

That main method will end up calling System.exit unless you define a system property "osgi.noShutdown".
You should instead call org.eclipse.equinox.launcher.Main#run(String[]).  (ie new Main().run(args) ).  

-Andrew




Tom Hsu <tom.hsu@xxxxxxxxxx>
Sent by: equinox-dev-bounces@xxxxxxxxxxx

01/09/2009 01:34 PM

Please respond to
Equinox development mailing list <equinox-dev@xxxxxxxxxxx>

To
Equinox development mailing list <equinox-dev@xxxxxxxxxxx>
cc

Subject
Re: [equinox-dev] Integrating plugin bundles in normal Java







Hi experts,

I have successfully my app A from another main POJO class like the following:

   public static void main(String[] args) {
       String[] launcherArgs = {
               "-configuration",
               "C:\\pathTto\\configuration",
               "-install",
               "C:\\pathToIntall",
               "-DJavaAgentLogConfigFile=C:\\pathToLogConfig\\log4j-commandline.xml",
               "-application",
               "org.my.Application",
       };
       org.eclipse.core.launcher.Main.main(launcherArgs);
   }

The above requires the use of startup.jar's org.eclipse.core.launcher.Main.main. However, I notice I do not have control once I called Main.main. I do not have a way for my App A to return the control to the calling main java file. I tried throwing an Exception in my app A to see if it will bubble up to the POJO main method, but it does not. I cannot use System.exit(0) since it terminates the whole JVM. snippet:
try {
org.eclipse.core.launcher.Main.main(launcherArgs);
} catch (Exception ex)
{
   System.out.println("I am done with app A");
}

in app A's terminate method:
terminate() {
  System.out.println();
  //System.exit();
  throw new RuntimeException("I am done. get me out of here");
}

What is a better way to achieve this? Bascially I want to run App A which through eclipse and use osgi from another program. Once App A is done, it needs to terminate and return control to the my POJO.

Regards,
Tom

Thomas Watson wrote:

I would recommend that you launch app A in a way that is consistent with the normal launch of eclipse. By that I mean use a configuration folder with a config.ini that is the same as if you are launching your application with the eclipse.exe. The config.ini configures a set of bundles into the framework for your application. You should be able to do something like this

       String[] equinoxArgs = { "-console", "-noExit",
             "-configuration" "/path/to/configuration",
             "-application", "myApp.Application"};
      BundleContext context = EclipseStarter.startup(equinoxArgs, null);
       Object appResult = EclipseStarter.run(null);


Tom



Inactive hide details for Tom Hsu ---10/29/2008 01:41:44 PM---Hi experts,Tom Hsu ---10/29/2008 01:41:44 PM---Hi experts,


From:

Tom Hsu
<tom.hsu@xxxxxxxxxx>

To:

equinox-dev@xxxxxxxxxxx

Date:

10/29/2008 01:41 PM

Subject:

[equinox-dev] Integrating plugin bundles in normal Java





Hi experts,

I am new to equinox so please excuse me for some obvious/stupid
questions. However, I am still trying to wrap my head around this module
system.

I am tasked with integrating an existing application A that is build
using bundles and equinox osgi in eclipse into another standalone Java
program B that will be traditional jar based program. I would like to
invoke the Equinox OSGi system to load these bundles/packages in the
standalone Java program through code and execute the main method of the
app A through program B.

My setup is as follows:
/plugins/ all the bundles that app A requires are here.
        also app A has a main bundle here

I can use Eclipse Application run option to launch it or comandline
"java -cp startup.jar org.eclipse.core.launcher.Main -
application myApp.Application ..."

However, I am exploring the option to launch app A with another existing
java program B. As a prototype, I am writing a plain POJO with main method:

  public static void main(String[] args) throws Exception {
      String[] equinoxArgs = { "-console", "-noExit" };
      BundleContext context = EclipseStarter.startup(equinoxArgs, null);
     
      String pluginDir = "
file:C:\\work\\";
      String commonJarName =
"org.eclipse.equinox.common_3.2.0.v20060603.jar";
      String configJarName =
"org.eclipse.update.configurator_3.2.2.R32x_v20070111.jar";
     
      Bundle commonBundle = context.installBundle(pluginDir +
commonJarName);
      Bundle configBundle = context.installBundle(pluginDir +
configJarName);
      configBundle.start();
     
      String jarName = "fetchlets.jar";
      String directoryPath = "
file:C:\\work\\plugins\\";
      String locationStr = directoryPath + jarName;

      Bundle bundle = context.installBundle(locationStr);
      bundle.start();
  }

However, my bundle fetchlets.jar cannot be started because, the
configurator bundle does not auto-discover all the required bundles in
the plugins directory. Can someone help me figure out if I can tell the
EclipseStarter to auto-load all bundles at a specific locations?

Or is there another approach I can use that is very similar to the run
options in Eclipse where setting the platform will suffice to load all
the plugins automatically?

I have been looking at:

http://www.eclipse.org/equinox/documents/quickstart.php
http://www.eclipsezone.com/eclipse/forums/t93976.rhtml


Regards,
Tom
_______________________________________________
equinox-dev mailing list

equinox-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/equinox-dev





_______________________________________________
equinox-dev mailing list
equinox-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/equinox-dev
 
_______________________________________________
equinox-dev mailing list
equinox-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/equinox-dev


_______________________________________________ equinox-dev mailing list equinox-dev@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/equinox-dev

Back to the top