`
javeye
  • 浏览: 331359 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Eclipse开发RCP应用程序中的一些问题

    博客分类:
  • RCP
阅读更多
problem
The key can be found in the message: '!MESSAGE Missing required bundle com.dawnatech.misc_0.0.0.' -- note the version number of 0.0.0.
answer
This is due to the fact that your 'misc' plugin is not defined in your quick launch configuration. These are tricky to get right..... I always define a specific quick launch configuration for all of my RCP apps.

I found that merely selecting the 'Launch an Eclipse application' link on the plug-in editor page usually doesn't set up the application and required plug-ins correctly at run time.

This also explains why you think it worked earlier but not later. This has happened to me, as well......

Go to Run | Run... page, create a new run configuration (and name it).
Then, set the Workspace Location to something appropriate for your machine, set the Program to run (product or application).

Then, go to the Plug-ins page and select the 'Choose plug-ins and fragments to launch....'. Deselect all, then select the two plugins in your product/application, and then select 'Add required plugins'.


Debugging a failed Eclipse launch



Every now and again, questions like "Why doesn't eclipse start?" are posted on the newsgroups, or "The application cannot be found". How do you go about debugging these scenarios? This isn't an exhaustive list, but may be a good place to start.

First, some background knowledge. Eclipse uses two writable areas for storing data; a configuration directory (which actually doesn't contain that much other than a config.ini and a few .dlls that have been extracted from bundles) and a workspace , which is usually in ~/workspace on Unix and c:\Documents and Settings\User\workspace on Windows. The workspace has two purposes; to act as a default place for any projects you create, and to have a .metadata directory for storing transient files, as well as anything you've configured in the Eclipse preferences, run-time caches, and a bunch of other stuff.

The config area is usually pretty harmless; if you delete it, it will get re-created on startup. Once created, it isn't usually changed. There's not usually much benefit in deleting the configuration directory, but there's not usually much harm in it either. A default install from unzipping the distribution from Eclipse doesn't have any configuration directory.

When Eclipse starts, it reads two files; eclipse.ini and configuration/config.ini . The former is a list of arguments that get passed to the JVM, whilst the latter is a list of name-value pairs that are set as system properties. If you want to run an Eclipse with an environment value set, you can put it in config.ini as org.example=foo or eclipse.ini as -Dorg.example=foo (after the 'vmargs' flag; if not present, you'll need to add it as an extra arg). Arguments are serparated by newline characters, so you can't put them on the same line. You can also supply these args on the command-line; eclipse -vmargs -Dorg.example=foo .

Eclipse logs all its messages to workspace/.metadata/.log. If you're in Unix, these are usually hidden, but they'll be there. Sometimes, when Eclipse isn't starting, it can help to delete this file first so that you're sure that any problems in starting the environment are not just random messages left over from before.

There's a secondary log, generated when Eclipse doesn't even get as far as starting. For example, if you specify a non-existent VM, then it won't get as far as running any Java code. In these cases, you can often find a configuration/123456.log which contains something useful. If Eclipse isn't starting and not generating a workspace/.metadata/.log file, check the configuration directory for anything suspicious.

The most likely scenario is one where the Eclipse VM starts, but then fails to find out what it's supposed to be doing and shuts down again. What to do then?

Well, clearly, the log may have some answers. Always a good place to look first, rather than guessing. If you do look and don't understand the output, generally posting the entire stacktrace to the newsgroup isn't the best way of finding out. You can generally find out what's going on just by reading the exception messages; and since Java's nested exception handling prints out the full stacktrace of each, you generally just want to scan down for the 'caused by' message at the top of each nested exception. In most cases, the answer is staring you in the face :-)

A good comand to run is:

egrep -A 2 "Caused by:|Exception:" workspace/.metadata/.log

If you're on a primitive OS without 'egrep' installed by default, use Cygwin to install that and other useful tools. Other variants of grep will work as well, but you might have to do two separate greps or miss out on the -A 2 (which prints out the two lines After as well).

It's 'normal' for there to be some errors in the log that are unrelated, so don't take it as read that that's the cause of the problem. Deleting the log before running will give you an idea of what's new, at least.

Some common messages:

NullPointerException ...


Oh joy. Nothing much to say here other than the code needs to be more defensive. Still, it's better than segfaulting, huh?

The bundle could not be resolved. Reason: Missing Constraint ...

Generally, you've got a newer version of a plug-in without its dependencies. For example, you had org.foo.lib-1.0.0 and org.foo.app-1.0.0 , and now that you've installed org.foo.app-1.0.1 it's stopped working. Chances are, org.foo.app-1.0.1 depends on org.foo.lib-1.0.1 or greater, and you've not got that installed. Using a kosher update site like Eclipse Europa discovery site shouldn't have these problems, but always something to be aware of.

java.lang.IllegalStateException: Workbench has not been created yet

This usually comes when someone tries to run a Java application against an OSGi bundle with java -classpath .... . It really means that the workbench plug-in hasn't started yet, and so calls to getWorkbench() fail. This is essentially a race condition, and can be solved by either expressing an explicit dependency on that bundle or bumping up that bundle to a higher start level than the workbench. Generally not seen, but if it is, that's what's happening.

Application "foobar" cannot be found in the registry. The applications available are:...

Either (a) you've mistyped the application ID, or more likely (b) the bundle that contributed the application can't be started. See below.

One or more bundles are not resolved because the following root constraints are not resolved:

Again, a problem with dependencies.

So, now that we know Eclipse is firing up a JVM, but not able to do anything else, where do we go? Well, time to drop into an OSGi console to find out more, or even look at what's going on in the log. Eclipse has a bunch of runtime options , and here are some of the most important ones:

-consoleLog

When starting, dump the messages to the console as well as the .metadata/.log file. Can be quite useful for quickly figuring out what's going on, especially if you don't know where the .metadata/.log file is being written (or assume that it's not being writable)

-noExit


Almost as useful as the last. Basically, even if the application can't be found or there's another problem, don't quit the JVM or OSGi engine. Can make the window hang around rather than disappearing on a Windows system.

-console or -console 1234

Start up an OSGi console interactively, or via a network socket 1234 (to which you can 'telnet localhost 1234' to gain access). Very useful if you're running on a remote machine or don't have access to the console from where Eclipse is being launched. Can do all manner of commands; see below for more.

-data /tmp/newplace or -data c:\temp\newplace

Run Eclipse, but with a workspace that's not the default location. Quite often, if this works but running without doesn't, indicates a problem with the workspace area.

-clean

Used to flush out some (but not all) entries in the workspace metadata area. A good thing to try, and generally safe, but doesn't always have the results intended. If you've not got any preferences, it's sometimes better just deleting the workspace/.metadata directly. If you have got prefs, either export them from the Window -> Preferences beforehand, or save *.prefs from the .metadata/.plugins/org.eclipse.core.runtime/.settings directories. Note that there's a bunch of stuff (like CVS repositories) that probably won't get saved like this; but you did take a backup first, right?

Windows users might also like to know about eclipsec , which isn't a compiler but rather a version of Eclipse that fires up a console window instead of hiding it away. Most of the time, running these with eclipsec is a good way of figuring out what's going on. Unix users can just use the eclipse one. For Mac users, there's a eclipse command you can access through Terminal instead of double-clicking the Eclipse.app .

So, you're through to the OSGi console. When it starts up, it will print out:

osgi>

From here, you can start to figure out what's going wrong. Typing '?' or 'help' will give you a list of available commands; if they scroll off the screen, type 'more' and you'll get paginated output.

Typing 'ss' (for ShortStatus) brings up a list of bundles that are available; they'll be in ACTIVE (running), RESOLVED (ready to run), STARTING (usually indicates a deadlock or stuck thread if you see that for any length of time) or INSTALLED. The last one is the one to look for; it means that the OSGi environment has found the bundle, but one or more of its dependencies haven't been met.

If you find a bundle in the INSTALLED state, you can use 'diag' (for DIAGnostics) to find out what's missing:

osgi> ss

Framework is launched.

id      State       Bundle

0       ACTIVE      org.eclipse.osgi_3.3.0.v20070530

1       ACTIVE      org.eclipse.equinox.common_3.3.0.v20070426

...

123   INSTALLED org.example.foo_1.0.0

...

osgi> diag 123

update@plugins/org.example.foo_1.0.0.jar [123]

  Missing imported package org.example.bar_0.0.0.

  Missing required bundle org.example.bar.core_0.0.0.



Quite often, if you've got an application that's not starting, it's because 'org.example.foo' defines the application; but the bundle can't start because it's got missing dependencies. The solution is therefore to resolve those dependencies (by installing a missing bundle or a bundle which exports the given package, and you should be away.

You can do this by restarting, or by dynamically adding it in via the console:


osgi> install http://www.eclipsezone.com/files/jsig/bundles/HelloWorld.jar

Bundle id is 456

osgi> start 456

Hello OSGi



You can also stop and start other bundles; once you've brought your dependencies in, you can restart the ones that failed before (e.g. start 123).

Occasionally, if the bundle is RESOLVED (i.e. all dependencies are met) but it still can't start (doing start 123 leads to an exception), then it implies the Bundle Activator's start() method has thrown an exception. That's basically either a programming or configuration error, outside the scope of this post. It's not always an error; for example, a plug-in that connects to a DB might (reasonably) be expected to have the property set via a command line property (e.g. -Ddatabase=foo) otherwise it won't work.

You can find out if there's a setting using 'getprop' in the console:

osgi> getprop osgi.nl

osgi.nl=en_UK



and even set it if it doesn't exist:

osgi> setprop database=foo

osgi> getprop database

database=foo



Of course, you can then do 'start 456' to see if the activator now works.

There's a bunch of other things you can do in the console; for example, if you wanted to see what application extension points were being contributed, you can do:

osgi> pt org.eclipse.core.runtime.applications

osgi> pt org.eclipse.core.runtime.applications

Extension point: org.eclipse.core.runtime.applications [from org.eclipse.equinox.app]

Extension(s):

-------------------

org.eclipse.ant.core.antRunner [from org.eclipse.ant.core]

...

org.eclipse.help.base.helpApplication [from org.eclipse.help.base]

...



You can also find out what extension points are contributed by a bundle:

osgi> ns org.eclipse.help

Extension point(s):

-------------------

org.eclipse.help.contentExtension [from org.eclipse.help]

org.eclipse.help.contentProducer [from org.eclipse.help]

org.eclipse.help.contexts [from org.eclipse.help]

org.eclipse.help.index [from org.eclipse.help]

org.eclipse.help.toc [from org.eclipse.help]



At least doing this will give you confidence that any extension points you've used will be contributed in the list somewhere. If not (or you have something like 'org.example.foo.org.example.foo.FooApp') then at least you can start debugging somewhere.

The last kind of error is more subtle to fix. If you see a message in the log like
The activator org.example.FooActivator for bundle org.example.foo is invalid , then this usually means there has been a ClassNotFoundException trying to load the class in the first place, before it's even got to the start() method.

CNFE is the bane of debugging; the only thing I can say is that it gets easier with practice. A key thing to understand is that if you have a class Foo, and that class references Bar as any kind of method parameter, return type or field type, then in order to load Foo, Bar must also be loaded. This is transitive, so if Bar needs to be loaded, then so does Flubber, and so on. Unfortuantely, when you hit a missing class, the actual class that can't be found is lost in the message and you just get back "Class Foo cannot be found", when clearly it can. Very often, the PDE will give you warnings when you're running into these problems at development time, but sometimes they can make their way past you and into a runtime bundle. Unfortunately, you have to go back to the code to figure it out.

In a bunch of cases, this has been caused by a developer adding a Jar to a Project's Java Build Path and not the OSGi Manifest dependencies. If you have (say) JUnit.jar added onto the build path, then the project will compile, but at run-time your activator will only consult the Bundle-ClassPath to find code. If it can't find JUnit.jar on that path, it will give up and give you the CNFE. The other possibility is that the Bundle-ClassPath either doesn't contain '.' (for classes in the bundle) or it does contain '.,JUnit.jar' but when exporting, the JUnit.jar is missing from the bundle itself. If it's the latter, check the entries in build.properties, and ensure that 'bin.includes=JUnit.jar' is in there. Very often, exporting the bundle and then opening it in WinZip will give you a clue as to what you expected to be in there (but wasn't) and/or consulting what the Bundle-ClassPath is in relation to the contents of the bundle itself.

So, whilst I don't think this will prevent any more questions being posted to the newsgroups in the future, at least it will be somewhere to point people to when they get stuck for reference. If you're experienced at debugging Eclipse startup problems and have any ideas that I've missed, please add comments to the below for the benefit of others. And if you find any glaring errors I've made, please add a comment so I can fix it :-)

I hope you've found this useful. Until next time
分享到:
评论

相关推荐

    ECLIPSE+RCP应用系统开发方法与实战(PDF 高岗著)

    《ECLIPSE+RCP应用系统开发方法与实战》这本书是高岗先生关于使用Eclipse RCP(Rich Client Platform)进行应用系统开发的一本实战指南。Eclipse RCP是Eclipse IDE的一部分,它提供了一个框架,使得开发者可以构建...

    开发您的第一个 Eclipse RCP 应用程序

    ### 开发您的第一个 Eclipse RCP 应用程序 #### 富客户端平台 (RCP) 概述 **Eclipse Rich Client Platform (RCP)** 是一个强大的框架,旨在利用 Eclipse 平台来构建非集成开发环境 (IDE) 类型的最终用户应用程序。...

    eclipse rcp应用系统开发方法与实战源代码.zip

    在"eclipse rcp应用系统开发方法与实战源代码.zip"中,我们可以学习到以下关键知识点: 1. **Eclipse RCP架构**:理解Eclipse RCP的基础架构非常重要,包括插件(Plugins)、工作台(Workbench)、视图(Views)、...

    使用Eclipse RCP进行桌面程序开发

    **Eclipse RCP** (Rich Client Platform) 是一种基于Java的开源框架,用于开发桌面应用程序。自从Eclipse 3.0版本以来,RCP逐渐成为构建高度定制化、功能丰富的桌面应用的标准平台之一。 **快速起步步骤**: 1. **...

    eclipse.rcp应用系统开发方法与实战(含源码)

    Eclipse RCP(Rich Client Platform)是Eclipse框架下的一个应用程序开发平台,它提供了一种构建强大、可扩展且用户友好的桌面应用的途径。Eclipse RCP的应用系统开发涉及多个核心概念和技术,包括组件模型、事件...

    eclipse icons,用来开发rcp桌面应用程序

    Eclipse Icons是Eclipse RCP(Rich Client Platform)开发中常用的一套图形用户界面资源,它们为Eclipse RCP应用程序提供了丰富的图标集,用于构建视觉上吸引人的且易于理解的用户界面。Eclipse RCP是一种基于Java的...

    Eclipse的RCP开发的入门教程

    其次,"使用Eclipse RCP进行桌面程序开发(一):快速起步.doc"文档将引导读者迅速进入实战阶段,讲解如何搭建开发环境,配置Eclipse IDE以支持RCP开发,以及如何创建和运行一个简单的RCP应用程序。这个文档通常会...

    开发你的第一个EclipseRCP应用程序汇编.pdf

    【开发你的第一个Eclipse RCP应用程序】 Eclipse Rich Client Platform(RCP)是Eclipse框架的一个组成部分,专门用于构建复杂的桌面应用程序。RCP利用Eclipse的插件体系结构,允许开发者创建具有高度可定制和可...

    eclipse开发rcp4应用示例

    在"eclipse开发rcp4应用示例"中,我们将探讨如何使用Eclipse RCP4构建一个应用程序,同时整合log4j日志系统以及自定义的启动画面(splashscreen)。 首先,了解Eclipse RCP4的基础架构至关重要。它基于OSGi服务,...

    eclipse 开发桌面程序

    SWT(Standard Widget Toolkit)是IBM Eclipse项目的一部分,作为一个强大的GUI编程框架,SWT为开发者提供了丰富的组件和API,使得开发高质量、高性能的桌面应用程序变得简单高效。与传统的AWT和Swing相比,SWT具有...

    Eclipse RCP 应用系统开发方法与实战

    7. **SQL在Eclipse RCP中的应用**:在"第12章+SQL.rar"中,可能详细讲解了如何在RCP应用中集成数据库访问。这可能包括使用JDBC驱动连接数据库、执行SQL查询、处理结果集以及事务管理等内容。 8. **实战案例**:...

    Eclipse RCP应用系统开发

    【Eclipse RCP应用系统开发】是针对软件开发领域中的一个特定技术,即Eclipse Rich Client Platform(Eclipse RCP)的深入探讨。Eclipse RCP是Eclipse框架下的一个开发平台,它允许开发者构建桌面应用程序,具有丰富...

    EclipseRcp 例子程序

    2. **工作台(Workbench)**:工作台是Eclipse RCP应用程序的中心,负责管理窗口、视图、编辑器等元素。开发者可以自定义工作台布局,例如添加新的视图或编辑器。 3. **视图(View)**:视图是用户界面中显示特定...

    eclipse RCP Plug-in开发自学教程.pdf

    eclipse RCP Plug-in开发自学教程 eclipse RCP(Rich Client Platform)是一...3. 能够独立开发RCP应用程序。 本教程旨在帮助读者自学Eclipse RCP插件式开发,提高开发效率和代码复用率,提高开发者的生产力和效率。

    Eclipse RCP开发教程

    Eclipse Rich Client Platform (RCP) 是一个用于构建桌面应用程序的框架,它基于 Eclipse IDE 平台,允许开发者利用 Eclipse 的强大功能和丰富的插件系统来创建自定义的、可扩展的应用程序。Eclipse RCP 的核心理念...

    Eclipse RCP 软件打包发布方法

    4. **集成JRE**:为了让Eclipse RCP应用程序在没有预装JRE的系统上运行,你需要包含一个JRE。在产品配置中,可以通过"Overview" -> "Runtime"选项卡来指定需要的Java版本。你可以选择捆绑一个特定版本的JRE,或者...

    Eclipse Rcp

    RCP作为一种客户端平台,其全称是Rich Client Platform,意味着一个包含必要插件的Eclipse运行时环境,它可以运行不依赖于Eclipse开发环境的应用程序。RCP应用通常拥有和Eclipse类似的外观与操作体验,例如动态的...

    Eclipse RCP应用系统开发方法与实战(第四章)

    在“Eclipse RCP应用系统开发方法与实战(第四章)”中,我们将深入探讨如何利用这个平台进行高效且灵活的应用程序开发。本章节主要关注的是实战经验与具体实现步骤,旨在帮助开发者掌握Eclipse RCP的核心概念和技术...

    Eclipse RCP 应用系统开发方法与实战 源代码

    工作台是RCP应用程序的核心,管理所有视图、编辑器和透视图。通过分析源码,我们可以学习如何定义和切换不同的透视图,以及如何在工作台上添加和管理UI元素。 4. **菜单和工具栏(Menus and Toolbars)** 菜单和...

Global site tag (gtag.js) - Google Analytics