Run OSGi Console of RCP Application (NOT the Host OSGi console) - eclipse

I need to check whether certain bundles loaded at startup inside my RCP Application. I know there is a "Host OSGi Console" that shows the states of all Plug-Ins within the Eclipse IDE, but I am not interested in those.
I performed the following steps to get the OSGi Console of my application itself:
Added the Plug-In "org.eclipse.equinox.console"
Created a OSGi Framework Configuration: Run Configuration -> OSGi Framework -> MyNewConfiguration
Run the configuration
When I validate the Plug-Ins, it says "Missing constraint: import package org.eclipse.felix.service.command". Where can I find this bundle?
Is this the correct way to open the OSGi Console of my custom RCP application? I'm not able to export the application as a product, so I can't run it outside of the Eclpse IDE.

Include bundles
org.eclipse.eqinox.console,
org.apache.felix.gogo.runtime,
org.apache.felix.gogo.shell
in your run configuration.
Also add option -console to your program arguments.
When developing it is sometimes useful to use option -debug and -consoleLog also.

Add the option -console to your program arguments.

For anyone coming late to the party...
In addition to org.eclipse.equinox.console you also need the org.eclipse.pde.ui plugin to be selected in your launch configuration. Use the 'Validate plugins' button as this generates some additional dependencies of its own (in Eclipse 2021-06) this list is:
org.eclipse.pde.launching
org.eclipse.jdt.core.manipulation
org.eclipse.jdt.debug.ui
org.eclipse.jdt.junit
org.eclipse.jdt.junit.core
org.eclipse.jdt.junit.runtime
org.eclipse.jdt.ui
org.eclipse.ant.launching
org.eclipse.ant.ui
org.eclipse.ui.trace
org.junit
org.hamcrest.core
You don't need to specify -console in the program arguments.

Related

Is there a difference between "starts" and "activates" for Eclipse RCP plugin?

When creating a plugin, in the manifest file there's an option to "Activate this plug-in when one of its classes is loaded":
Also, when configuring a product, there's also option to specify plugin Start Levels:
Is the concept of "starting" the same or different than "activating". If they're different, how so?
Start Levels are used to control the order in which plug-ins are started when Eclipse itself is starting up. This is necessary to ensure that some services are available when they are needed. The picture below shows the default start levels. At level 1 org.eclipse.equinox.simpleconfigurator is the plug-in that loads most of the other plug-ins - so it needs to start first!
'Activate this plug-in when one of its classes is loaded' is an option to control when the plug-in Activator class is called (if it has one). If this is specified the activator is not called until something needs to use one of the other classes in the plug-in. If not specified the Activator will only be called if the plug-in is started by 'Auto-Start' in the start levels or an explicit OSGi start call.
Note that many plug-ins don't need an Activator at all.

How do I make Eclipse and mvn appengine:devserver talk to each other?

I am in the process of switching from Google Plugin for Eclipse to the official Google App Engine Maven Plugin.
The last thing, I hope, that I cannot figure out is how to get a good debug workflow set up. When I was using GPE, I just set breakpoints and the debugger stopped there automagically, but when I run the dev server via mvn appengine:devserver, I don't think the dev server and eclipse are aware of each other.
How do I make them talk to each other?
The first option is to set up your project to use WTP as documented # https://cloud.google.com/appengine/docs/java/webtoolsplatform. This is the method I switched to.
The second option is to use two debug configurations.
The first debug configuration will run your maven target, namely appengine:devserver.
The second is a Remote Java Application configuration, and will connect the debug client to the devserver jvm.
This also requires some jvm args to be passed to the maven goal.
<!-- GAE plugin -->
<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>1.7.5-SNAPSHOT</version>
<configuration>
<jvmFlags>
<jvmFlag>-Xdebug</jvmFlag>
<jvmFlag>-Xrunjdwp:transport=dt_socket,address=1044,server=y,suspend=y
</jvmFlag>
</jvmFlags>
<disableUpdateCheck>true</disableUpdateCheck>
</configuration>
</plugin>
Once those 3 things are in place, run the maven debug configuration, then run the debug client configuration, then exercise your application.
There is no support for hotswap yet, so if you change any non-resource files(any java source), the devserver will not see them. Resource files will get deployed(static files: html, js).
You should be executing mvn from eclipse in debug mode.
In Eclipse you can configure such maven build commands from eclipse top toolbar "Run" -> "Debug Configuration" -> "Maven Build"
Once in maven is launched in eclipse debug mode you should be able to hit the breakpoints.
Edit -
One other option is to set up Remote Debug i.e "Run" -> "Debug Configuration" -> "Remote Java Application" and listen remote debug port i.e You should ensure appengine:devserver launches with remote debug port arguments - Reference - Remote Debugging in eclipse
This question may give you a hint of the problem. The Maven appengine:devserver starts the development server on a separate process. Eclipse however is only aware of the Maven process itself (this is what you see in the debug view). In addition, since the dev server cannot be started with arguments such as a debug port, it probably can never be connected to a debugger.
The question linked suggest that there's an unofficial Maven GAE plugin which takes arguments. There's also a new ticket to enhance the official plugin and a promise by the plugin developper to implement this feature soon.
I'll see what else I can do to make the eclipse integration easier, but there is now an update to the issue filed to the appengine-maven-plugin project : http://code.google.com/p/appengine-maven-plugin/issues/detail?id=3&can=1 so take a look and see if the support for the jvm arguments can help you out.
Please let me know your experiences, I'm always in favor of things being awesome.
Answer Relevant in 2015
I created a GAE (Java) project in Sep 2015 and the following applies to this and similar projects.
I started by creating my project as on ordinary GAE maven project using the Skeleton archetype by simply following the relevant steps from Using Apache Maven - Java — Google Cloud Platform. Followed through from Requirements through to Testing your app with the development server.
After that I imported this project into Eclipse JEE (Mars) using "Import an existing Maven project". Started development.
When I needed to debug, I only had to carry out the few steps explained below.
Create a debug configuration
Go to Run -> Debug Configurations, click on Remote Java Application and create a new configuration by clicking on the New button (see screenshot, upper left corner above filter text box).
Fill in the details by choosing your particular project and giving a suitable name to the configuration as shown below (let port be 8000) and click Apply:
Uncomment some lines in pom.xml
In your project's pom.xml, find the configuration for plugin appengine-maven-plugin and uncomment the following lines:
<jvmFlags>
<jvmFlag>-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n</jvmFlag>
</jvmFlags>
Run the mvn appengine:devserver command from the command line
As the title says...
Attach the debugger from within Eclipse
Click on the little down-triangle next to the button for Debug and choose the name of the debug configuration you just set up ("HelloWorldServlet" in my example).
I roughly follow the steps # developers.google.com/appengine/docs/java/webtoolsplatform in favor of my previous method.

OSGi + Logback + slf4j - Eclipse Run Configuration

Here is my configuration:
We are developing an OSGi application and want to include logging. I decided to use slf4j + logback.
We are using Eclipse as an IDE and Tycho to benefit from the Eclipse IDE like Manifest Editor and so on.
So I have tried the following:
Created a new plugin with the following Manifest.mf:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Createcommand
Bundle-SymbolicName: de.hswt.oms.ws.wsr.createcommand
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Import-Package: de.hswt.oms.ws.command.wsr,
de.hswt.oms.ws.ds.core.data.impl,
org.slf4j
Service-Component: OSGI-INF/component.xml
Now when i move to Run -> Run Configurations -> OSGi Framework and select my Bundle and click "Add Required plugins" more than 100 Bundles will be selected and I get a lot of errors and exceptions.
So I came up with a new plugin from existing Jars which include the following three jars:
logback-classic-1.0.7
logback-core-1.0.7
com.springsource.slf4j.api-1.6.1 (I dont believe this is a good idea, but hey...)
If I create a new run configuration manually (not clicking "add required bundles" it works as expected but as far as I click "add required bundles" I come back to the more then 100 Bundles with a lot of errors (some Jetty stuff for example...)
So my Question is: How can I enable logback and slf4j in my OSGi application and use it within eclipse and configure it properly?
If you need more information please feel free to ask.
AFAIK there are some issues in the bundle manifest header in the current official Logback/SLF4J jars. However, you only need the following three jars/bundles. No other are required for the basic functionality.
SLF4J API
Logback Core
Logback Classic
At Eclipse we put the bundles in Orbit for re-use across projects. We apply some modifications to the manifest header that we think are beneficial. For example, we deliver the actual SLF4J binding as a fragment to avoid the circular dependency of the original SLF4J API jar.
Here are the download links to the bundles:
org.slf4j.api
ch.qos.logback.core
ch.qos.logback.classic
ch.qos.logback.slf4j
You may also want:
org.slf4j.ext
org.slf4j.jcl (Commons Logging via SLF4J)
org.slf4j.jul (Java Logging Bridge)
org.slf4j.log4j (LOG4J via SLF4J)
Please note that "Add Required plugins" is not smart enough. It may select too many or too few plug-ins. Sometimes service API is delivered in one bundle but the actual service implementation is delivered in a second bundle. It may not select that bundle.
There is a checkbox saying something like 'Resolve optional imports'. It's on by default, but that pretty much always results in the behaviour you describe, that it wants to add everything.
Switching that off should help. also, PDE tends to add a lot of fragments that are not needed.
All in all, I rarely trust Eclipse with adding the 'right' bundles for runtime. I just use 'validate' and add whatever is needed manually, and check again. It might take a few minutes but figuring out what went wrong when you leave it to PDE can take hours.
Not sure about logback but you may also want to try pax logging. Just install pax logging api and pax logging service and it should work. There is also a documentation how to set it up in eclipse.
If you want it to use with Eclipse Equinox, you could try the Eclipse-BuddyPolicy. This enables one plugin to load all classes from another plugin without importing it explicitly.
This may solve your problem.
Add to your Manifest from the bundle with the jars:
Eclipse-BuddyPolicy: dependent
and to the bundle using the logging
Eclipse-RegisterBuddy: com.other.plugin
see http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fmisc%2Fbundle_manifest.html

Eclipse rcp plugin added to the target can be resolved at compile time, but not run time

I've added a plugin to the target platform of my RAP application. I can reference it without issue without any problems while working on the project, and the compile happens without errors. The plugin also shows up in the plugin dependiencies library of my build path. However, when I run the application, the osgi framework gives me the exceptionA
org.osgi.framework.BundleException: The bundle "ate_rap_1.0.0.qualifier [98]" could not
be resolved. Reason: Missing Constraint: Require-Bundle: com.richclientgui.rcptoolbox;
bundle-version="0.0.0"
How do I add a plugin so that I can use it with my application?
First of all, do not use plugin dependencies when you work with OSGi. OSGi doesn't know about your those dependencies in your IDE, it only cares for the dependencies that a bundle defines in its bundle manifest. Therefore, you have to define a dependency in the MANIFEST.MF (Dependencies tab) instead.
Second, you have to add this bundle to your launch configuration. In Eclipse, go Run... -> Run Configurations... Select your launch config, go to the Bundles tab and check your additional plug-in. Before you launch, click on "Validate Bundles" in the Bundles tab.
Is your application built from a PDE feature? If so you may need to add the new plugin to the list of plugins included in your main feature.
To add a plugin to a basic RAP application, select File->New->Other and in the wizard, select Plug-in Development->Plug-in from Existing Jar Archives. This will create a project hosting that plugin which may be added to the build path. After adding to the build path, add this plugin as a dependencies in your MANIFEST.MF. Finally, in the run configuration for the application, select the Bundles tab and make sure the bundle you want to add is checked. This is easily done with the "Add Required Bundles" button. Now the project should run in Eclipse with the bundle.

How to add build steps to Eclipse "run configuration"?

Is there a way to add build steps to a "run configuration" in Eclipse?
My project uses an applet that should be built before starting the web application. So I'd like to configure Eclipse to do this single step before actually running the application.
I know I can do it with Ant/Maven, but I wonder if there's a way to do it in Eclipse.
Thanks
For a classic launching (Java or Java Applet) configuration, no. Not directly.
For an External Tols launcher, not directly either.
The idea would be:
to not build your applet every time you modify your main project
make sure it is built when you want to launch your webapp.
For that, you could define two projects:
one for the compilation of your main project.
the second (depending on the first) for the compilation of your applet.
Your launching configuration would then run with the second project (which includes the first)
If the option "Build automatically" is selected, the second project shouldn't run without being compiled first.