如何将自定义 MIME 内容类型添加到 Eclipse RCP 应用程序
我有一个使用 MIME 格式传递消息的客户端/服务器系统。我使用 JavaBeans 激活框架创建了一些自定义 mimetypes。
我创建了一个简单的 java 项目,其中包含以下内容:
my-mime
+- src/com/foo/FooContentHandler
+- META-INF/mailcap
+- META-INF/mime.types
mailcap:
application/x-foo; ; x-java-content-handler=com.foo.FooContentHandler
mime.types:
type=application/x-foo desc="foo" exts="foo"
我已经在独立的测试用例中演示了这一点。但是,当我将其添加为插件时,MIME 类型不会被选中。我认为这是因为 Java 激活类看不到我的自定义 mime 类型定义。
如何将它们添加到我的捆绑包中以便被拾取?
I have a client/server system that is passing messages using MIME format. I have created some custom mimetypes using the JavaBeans activation framework.
I have created a simple java project with the following:
my-mime
+- src/com/foo/FooContentHandler
+- META-INF/mailcap
+- META-INF/mime.types
mailcap:
application/x-foo; ; x-java-content-handler=com.foo.FooContentHandler
mime.types:
type=application/x-foo desc="foo" exts="foo"
I have demonstrated this working in a standalone testcase. However, when I add it as a plugin the MIME type doesn't get picked up. I presume that this is down to the fact that the Java Activation classes can't see my custom mime type definitions.
How can I add them to my bundle so that they are picked up?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
确保您的项目是插件项目,并确保 build.properties 将您的 mailcap 和 mime.types 检查为导出(打开清单并使用“构建”选项卡)。
Make sure your project is a Plugin Project, and make sure the build.properties has your mailcap and mime.types checked as exported (open the manifest and use the Build tab).
我知道你问这个问题已经有一段时间了,但无论如何......
看起来你的 RCP 应用程序无法读取该文件。
首先,确保
mailcap
和mime.types
资源属于尝试访问它们的同一个插件。其次,尝试使用 显式 MIME 类型文件规范。
从静态文件和绝对文件路径开始,例如
/tmp/mime.types
,如果有效,那么您的问题确实是资源加载。在这种情况下,从插件获取流并且< a href="http://docs.oracle.com/javase/6/docs/api/javax/activation/MimetypesFileTypeMap.html#MimetypesFileTypeMap%28java.io.InputStream" rel="nofollow">使用该流构建您的MimetypesFileTypeMap
。I realize it's been a while since you asked this question, but anyway...
Looks like your RCP application cannot read the file.
First, make sure the
mailcap
andmime.types
resources are owned by the same plug-in that tries to access them.Secondly, try to construct
MimetypesFileTypeMap
with explicit mime-type file specification.Start with static file and absolute file path e.g.
/tmp/mime.types
and if that works then your problem is resource loading indeed. In that case, get stream from plugin and construct yourMimetypesFileTypeMap
with that stream.在我的项目中,我有两个 RCP 插件。其中一个包含
Java Mail
jar 及其所有依赖项,包括activation.jar
。另一个包含用于撰写和发送邮件的自定义代码。最初,我尝试在第二个插件中使用
MimetypesFileTypeMap
并使用类方法getContentType(String filename)
识别 MIME 类型。mime.types
文件被放置在插件的 META-INF 文件夹中。问题几乎是一样的。当从 IDE 启动 RCP 应用程序时,MIME 类型识别工作正常,但当作为导出 RCP 应用程序启动时,MIME 类型识别失败。但后来我发现 Java Mail 会尝试识别 MIME 类型而不是它本身,例如在将文件附加到电子邮件时。它使用其依赖项
activation.jar
。之后,我需要解决如何强制activation.jar
在第一个插件的范围内找到正确的mime.types
的问题。但我发现的唯一方法是重新打包
activation.jar
并在 jar 的 META-INF 文件夹中添加正确的mime.types
。不幸的是,这个解决方案并不完美,因为它“破解”了第三方库。In my project I had two RCP plugins. One contained
Java Mail
jar and all its dependencies, includingactivation.jar
. Another contained custom code for composing and sending mails.Initially, I tried to use
MimetypesFileTypeMap
in the second plugin and identify MIME type using class methodgetContentType(String filename)
.mime.types
file was placed in plugin`s META-INF folder. The problem was almost the same. MIME types identification worked perfectly when RCP app was launched from IDE, but failed when it was launched as export RCP app.But then I find out that Java Mail tries to identify MIME types but itself while, for example, attaching files to an email. And it uses its dependency
activation.jar
. After that I needed to solve the problem about how to forceactivation.jar
to find correctmime.types
in the scope of the first plugin.But the only way I found was repackaging
activation.jar
and adding correctmime.types
in jar`s META-INF folder. Unfortunately, this solution is not perfect as it "hacks" third-party library .来自 https://docs.oracle.com/cd/E17802_01/j2se/javase/technologies/desktop/javabeans/glasgow/javadocs/javax/activation/MailcapCommandMap.html
来自现已失效的链接:
From https://docs.oracle.com/cd/E17802_01/j2se/javase/technologies/desktop/javabeans/glasgow/javadocs/javax/activation/MailcapCommandMap.html
From a now-dead link: