您的位置:首页 > 编程语言 > Java开发

关于ActiveMQ在MyEclipse中出现无法读取schema文档的问题解决方法

2010-09-19 10:34 323 查看
由于项目要使用到邮件功能,老大就叫我用ActiveMQ来管理邮件的发送,其好处网上百度,这里不说了,我想说说网上有好多号称可以运行的Spring+ActiveMQ的例子,下载下来后发现每个例子的**applicationContext.xml都在MyEclipse中出现错误(红点提示---看到就头痛了),几乎试验过所有的中文解决方法了,还是没法解决,大家都可以从英文提示那里知道IDE找不到schema文档,无法读取jar包里的activemq.xsd文件所引发。
找了一天的方法,还是那样,红点依旧,很沮丧,本人经受不起打击,这次的打击不小了。中文的方法无法解决,没办法,只好去试试英文的。本人英文不太好,只能死马当活马医了,很快就发现了个解决方法,原来之前试验过的一个中文方法的方向是正确的,不过不知道是那篇中文文章的作者手误还是不负责 :twisted: ,可以肯定他没有试验过就发布的,不然怎么还是出现红点错误,而且一个错误,网上千千万万篇文章都是那样的复制、黏贴转载。给不少的新手带来了障碍。

以下是从英文网站复制过来的----将一些认为是重点的翻译一下

Newer versions of ActiveMQ have support for XML name space schema declarations to allow easier configuration of container beans. Adding the following XMLNS declaration to the beans container will allow you to use ActiveMQ’s amq name space.

XML:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:amq="http://activemq.apache.org/schema/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://activemq.apache.org/schema/core
http://activemq.apache.org/schema/core/activemq-core.xsd">

<amq:broker start="true" brokerName="bs-localhost">
<amq:networkConnectors>
<!−− more configurations −−>
</amq:networkConnectors>
</amq:broker>

</bean>

When the application is deployed (in Tomcat) it will work as expected, however if you try to run it under Eclipse the container fails to start with the message:

org.xml.sax.SAXParseException: schema_reference.4:
Failed to read schema document 'http://activemq.apache.org/schema/core/activemq-core.xsd',
because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not .

Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.c:
The matching wildcard is strict,
but no declaration can be found for element 'amq:broker'. </xsd>

The amq:broker maybe replaced with amq:connectionFactory depending on which name elements you have actually used.


[color=red]In order for Eclipse to understand the amq name space you must add xbean support for ActiveMQ. This is achieved by adding xbean-spring-3.4.jar to your dynamic web project.[/color]
[color=green]在项目中添加xbean-spring-3.4.jar是为了让Eclipse能知道ActiveMQ的amq的命名空间[/color]


According to the ActiveMQ website the XSD declaration will be automatically fished out of the jar and used to help Eclipse give you features like command completion for the XML schema. In fact what happens, is that Eclipse lights up like a Christmas tree moaning that it can’t find the schema declaration. Below is a set of instructions to tell Eclipse how to associate the activemq-core.xsd url with the activemq-core.xsd found in the jar file which is shipped as part of ActiveMQ.

1. Select Windows->Preferences from the Eclipse menu bar.
2. Select XML->XML Catalog from the left hand configuration tree.
3. Highlight User Specified Entries and select Add.
4. The Add XML Catalog Entry windows appears.
5. In the Location enter the path to the activemq-all jar, then add !/activemq.xsd to the end of the jar name. e.g. jar:file:[color=red]C:/Java/libs/activemq/apache-activemq-5.2.0/activemq-all-5.2.0.jar!/activemq.xsd[/color]
[color=green]以上这段中C:/Java/libs/activemq/apache-activemq-5.2.0/activemq-all-5.2.0.jar!/activemq.xsd的C:/Java/libs/activemq/apache-activemq-5.2.0替换为自己的acticemq-all.jar的绝对路径,activemq-all-5.2.0.jar改成自己对应的包名便可以。中文方法都是写<path for activemq>\,什么也不说明下,严重鄙视他们,很不负责[/color]
6. Under KeyType enter Namespace Name
7. and under Key enter http://activemq.apache.org/schema/core
8. then click Ok.
9. Now we need to do the same for the other name space file, so hit Add again.
10. In the Location enter the path to the activemq-all jar, then add !/activemq.xsd to the end of the jar name. e.g. jar:file:C:/Java/libs/activemq/apache-activemq-5.2.0/activemq-all-5.2.0.jar!/activemq.xsd
11. Under KeyType enter Schema Location
12. and under Key enter http://activemq.apache.org/schema/core/activemq-core.xsd
13. Click Ok, Ok.

The Spring IDE should do its thing and the red error markers will disappear.

相信大家都应该解决困扰很久的问题,我也还要继续学习ActiveMQ的使用,很高兴与大家分享经验、交流技术 阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐