Java 捆绑的激活器无效
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1305307/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The activator for bundle is invalid
提问by penguru
I'm trying to create a simple plugin in eclipse. When I run the application, I see this error in log file:
我正在尝试在 Eclipse 中创建一个简单的插件。当我运行应用程序时,我在日志文件中看到此错误:
org.osgi.framework.BundleException : The activator for bundle org.x.y.Activator for bundle org.x.y is invalid.
org.osgi.framework.BundleException :bundle org.xy 的 bundle org.xyActivator 的激活器无效。
Do you have any idea about this error?
你对这个错误有什么想法吗?
采纳答案by VonC
Check your build.properties
section
检查您的build.properties
部分
If it doesn't properly specify what's supposed to be in the final binary result, it will not work. Check the .class files are where the MANIFEST.MF says they will be.
如果它没有正确指定最终二进制结果中应该包含的内容,它将无法工作。检查 .class 文件是否位于 MANIFEST.MF 所说的位置。
from EclipseZone, another reason for this error message:
来自EclipseZone,此错误消息的另一个原因:
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.
,那么这通常意味着
ClassNotFoundException
首先尝试加载类,甚至在它到达 start() 方法之前。
penguruadds:
彭古鲁补充说:
The error occurs when I try create a new object from any other class in the constructor of activator class. Isn't it legal to create an object in activator plugin ?
当我尝试从激活器类的构造函数中的任何其他类创建新对象时,会发生错误。在激活器插件中创建对象不合法吗?
- If that class if from another plugin which has not yet been "activated", that could be your problem.
- If that class is not found, that would also invalidate your plugin activator.
- 如果该类来自另一个尚未“激活”的插件,那可能是您的问题。
- 如果未找到该类,那也会使您的插件激活器无效。
Basic advice: you may be better off with your initializations done in the start()
methodof Activator
rather than its constructor.
基本建议:在start()
方法中Activator
而不是在其构造函数中完成初始化可能会更好。
回答by penguru
I found the reason of the error. The error occurs when i try create a new object from any other class in the constructor of activator class. Isn't it legal to create an object in activator of plugin ?
我找到了错误的原因。当我尝试从激活器类的构造函数中的任何其他类创建新对象时发生错误。在插件的激活器中创建对象是否合法?
回答by Peica
If you have move the eclipse workspace to a new path, then you should use the project->clean before your plugin build, Or you would meet this problem.
如果您已将 eclipse 工作区移动到新路径,那么您应该在构建插件之前使用 project->clean,否则您会遇到此问题。
回答by A Nair
I also faced same issue while importing plugins from different workspace. Basically, it is the bundle classpath where the framework looks for while loading the classes. When you import to a different workspace, make sure you change the class path to point to appropriate location i.e. where the class file are present.
从不同的工作区导入插件时,我也遇到了同样的问题。基本上,它是框架在加载类时查找的包类路径。当您导入到不同的工作区时,请确保将类路径更改为指向适当的位置,即类文件所在的位置。
After modifying the classpath try to clean and re-build and re-run. It should work..hopefully..
修改类路径后尝试清理并重新构建并重新运行。它应该工作..希望..
回答by Jared
OK, I hate to be captain obvious here, but I've made this mistake before. This can also happen when you forget to extend BundleActivator.
好吧,我讨厌在这里成为明显的队长,但我以前犯过这个错误。当您忘记扩展 BundleActivator 时,也会发生这种情况。
回答by Libor Jelinek
In my case this exception was because of inability of Eclipse custom class loader to resolve and load all depending classes from other plugins in-time. I am not Eclipse super-guru so maybe it was my fault.
在我的情况下,此异常是因为 Eclipse 自定义类加载器无法及时解析和加载来自其他插件的所有依赖类。我不是 Eclipse 超级大师,所以也许这是我的错。
However it was fixed by disabling lazy loading of plugin. In GUI on Overviewtab of MANIFEST.MF
editor uncheck Activate this plug-in when one of its classes is loaded. Or directly in MANIFEST.MF
delete line
但是它是通过禁用插件的延迟加载来修复的。在 GUI编辑器的概览选项卡上MANIFEST.MF
取消选中Activate this plug-in when its classes is loaded。或者直接在MANIFEST.MF
删除行
Bundle-ActivationPolicy: lazy
回答by Guu
I spent some time with this problem. Finally I noticed that the ClassNotFoundExceptions were not in line with my code, they were coming from wrong (old) packages. I checked if there was some other plugin which was messing with my debugs/exports and indeed there was, my own plugin!
我花了一些时间解决这个问题。最后我注意到 ClassNotFoundExceptions 与我的代码不一致,它们来自错误的(旧)包。我检查了是否有其他插件干扰了我的调试/导出,确实有,我自己的插件!
So a simple fix to try if you're facing this and the CNFE's are not in line with your code:
因此,如果您遇到此问题并且 CNFE 与您的代码不符,请尝试一个简单的修复:
- Go to "Install new software"
- Click on "already installed"
- Remove all instances of your package/plugin and restart
- 转到“安装新软件”
- 点击“已经安装”
- 删除包/插件的所有实例并重新启动
Likely this was caused because I changed the plugin ID, making Eclipse treat it as a new plugin.
这可能是因为我更改了插件 ID,使 Eclipse 将其视为新插件。
Another good site to take a look if you're getting frustrated and stuck: http://www.eclipsezone.com/eclipse/forums/t99010.html
如果您感到沮丧和卡住,可以查看另一个好网站:http: //www.eclipsezone.com/eclipse/forums/t99010.html
回答by koppor
Another captain obvious: If you change the paths of your source files (e.g. src/ to src/main/java), but forget to update build.properties, the compilation will always succeed, but your plugin will never work.
另一个明显的队长:如果您更改源文件的路径(例如 src/ 到 src/main/java),但忘记更新 build.properties,编译将始终成功,但您的插件将永远无法工作。
回答by Christian
I had the same error, in my case I created my own constructor with parameters. But I didn't provide a default constructor. So after removing my constructor and initialized all within the start() method, it worked like charme.
我有同样的错误,在我的情况下,我用参数创建了自己的构造函数。但是我没有提供默认构造函数。因此,在删除我的构造函数并在 start() 方法中初始化所有内容之后,它就像魅力一样。
回答by Matthias H
In my case there was this Message "Activator ..invalid" but in the next exceptions there were ClassNotFound Exceptions in a Bundle were i didnt change something..
在我的情况下,有此消息“Activator ..invalid”,但在接下来的例外中,Bundle 中有 ClassNotFound Exceptions 我没有更改某些内容..
Guu(Posted a solution too) is my hero, After increasing
Guu(也发布了一个解决方案)是我的英雄,增加后
Bundle-ManifestVersion: 2
to
到
Bundle-ManifestVersion: 3
everything works :)
一切正常:)