Java Eclipse 上的 Maven 项目警告“DTD 或 XML 架构”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1980934/
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
eclipse on maven project warning 'DTD or XML schema'
提问by cometta
Description Resource Path Location Type
No grammar constraints (DTD or XML schema) detected for the document. TEST-net.kindleit.gae.example.server.MessageRepositoryTest.xml /projecttest-gae-example/target/surefire-reports line 1 XML Problem
No grammar constraints (DTD or XML schema) detected for the document. appengine-web.xml /projecttest-gae-example/src/main/webapp/WEB-INF line 1 XML Problem
No grammar constraints (DTD or XML schema) detected for the document. appengine-web.xml /projecttest-gae-example/target/projecttest-gae-example-1.0-SNAPSHOT/WEB-INF line 1 XML Problem
No grammar constraints (DTD or XML schema) detected for the document. datastore-indexes-auto.xml /projecttest-gae-example/WEB-INF/appengine-generated line 1 XML Problem
No grammar constraints (DTD or XML schema) detected for the document. jdoconfig.xml /projecttest-gae-example/src/main/resources/META-INF line 1 XML Problem
No grammar constraints (DTD or XML schema) detected for the document. jdoconfig.xml /projecttest-gae-example/target/projecttest-gae-example-1.0-SNAPSHOT/WEB-INF/classes/META-INF line 1 XML Problem
No grammar constraints (DTD or XML schema) detected for the document. webapp-cache.xml /projecttest-gae-example/target/war/work line 1 XML Problem
how to fix the above problem on eclipse? my project is maven based. Is it because I miss out some dtd files? how to include it?
如何解决eclipse上的上述问题?我的项目是基于 Maven 的。是因为我错过了一些 dtd 文件吗?如何包含它?
example jdoconfig.xml
示例 jdoconfig.xml
<?xml version="1.0" encoding="utf-8"?>
<jdoconfig xmlns="http://java.sun.com/xml/ns/jdo/jdoconfig"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig">
<persistence-manager-factory name="transactions-optional">
<property name="javax.jdo.PersistenceManagerFactoryClass"
value="org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManagerFactory"/>
<property name="javax.jdo.option.ConnectionURL" value="appengine"/>
<property name="javax.jdo.option.NontransactionalRead" value="true"/>
<property name="javax.jdo.option.NontransactionalWrite" value="true"/>
<property name="javax.jdo.option.RetainValues" value="true"/>
<property name="datanucleus.appengine.autoCreateDatastoreTxns" value="true"/>
</persistence-manager-factory>
</jdoconfig>
采纳答案by VonC
Initial answer (Dec. 2009)
初步答复(2009 年 12 月)
If you have WTP (with the XML part included):
如果您有 WTP(包括 XML 部分):
Preferences->Validation->XML Validator-> unclick manual and/or buildshould prevent eclipse checking the DTD
Preferences->Validation->XML Validator-> unclick manual and/or build应该防止eclipse检查DTD
Or:
或者:
From the Preference page, choose XML > XML Files. Under the section "Validating files" you can change the severity in the drop down from Warning to Ignore. Just note that this is for all XML files, not just
build.xml
. But you can just addbuild.xml
to the exclude filter if you would still like this warning for other XML files.
从首选项页面中,选择 XML > XML 文件。在“验证文件”部分下,您可以将下拉列表中的严重性从警告更改为忽略。请注意,这适用于所有 XML 文件,而不仅仅是
build.xml
. 但是,build.xml
如果您仍然希望对其他 XML 文件发出此警告,则可以添加到排除过滤器。
Update (Feb. 2012)
更新(2012 年 2 月)
Someone made in the comments (now deleted) the valid point that you should Never ignore warnings.
But Fix them!
有人在评论(现已删除)中提出了您永远不应该忽略警告的有效观点。
但是修复它们!
When ask how, he goes on (emphasis mine):
当被问及如何时,他继续(强调我的):
I'd fix Eclipse because this is clearly a sign of bad design.
For example I might report a bug to Eclipse Foundation bug tracker.
Eclipse needs to add "sane" defaults for Spring/Java EE project files that are "known" to have no need of XML grammars.
Either something is wrong with the file or Eclipse is broken somewhere.
Three problems I had:
- with
Log4j.xml
file, saying it cannot find the XML definition forlog4j.dtd
although the file is in the system path where the Validator looks- Ant
build.xml
file says I have no grammar constraints- for some reason I can't clean the project.
我会修复 Eclipse,因为这显然是糟糕设计的标志。
例如,我可能会向 Eclipse Foundation 错误跟踪器报告错误。
Eclipse 需要为“已知”不需要 XML 语法的 Spring/Java EE 项目文件添加“合理”默认值。
要么文件有问题,要么 Eclipse 在某处损坏。
我遇到的三个问题:
- 与
Log4j.xml
文件,说它找不到 XML 定义,log4j.dtd
尽管该文件位于验证器查找的系统路径中- Ant
build.xml
文件说我没有语法限制- 出于某种原因,我无法清理该项目。
There are actually bugs discussing strategies/bugs around those warning:
实际上存在围绕这些警告讨论策略/错误的错误:
- bug 218326: ""No grammar constraints" warnings for system files in the Problems view" did take the "exclusion route"
- bug 331749complains about "No grammar constraints" even though directory is excluded
- 错误 218326:“问题视图中系统文件的“无语法约束”警告确实采用了“排除路线”
- 即使排除了目录,错误 331749 也会抱怨“无语法限制”
Obviously, more fixes are required regarding the management of those warnings.
显然,需要对这些警告的管理进行更多修复。
回答by bmargulies
It's just a warning. In preferences: XML/XML Files/Validation, you can turn it off.
这只是一个警告。在首选项:XML/XML Files/Validation 中,您可以将其关闭。
回答by Pascal Thivent
How to fix the above problem on eclipse?
如何解决eclipse上的上述问题?
It's more a warning than an real problem. You can tell Eclipse to ignore this when validating files (Windows > Preferences > XML > XML Files > Editor > Validation).
这与其说是一个真正的问题,不如说是一个警告。您可以告诉 Eclipse 在验证文件时忽略它(Windows > Preferences > XML > XML Files > Editor > Validation)。
Is it because I miss out some dtd files?
是因为我错过了一些 dtd 文件吗?
No, it's because the XML document doesn't declare any DTD or XSD.
不,这是因为 XML 文档没有声明任何 DTD 或 XSD。
How to include it?
如何包含它?
You could of course add the declaration manually (if you know which DTD or Schema to add). Or you could tell Eclipse to ignore the fact that no grammar is specified as previously mentioned. Or you could just live with it.
您当然可以手动添加声明(如果您知道要添加哪个 DTD 或架构)。或者您可以告诉 Eclipse 忽略前面提到的没有指定语法的事实。或者你可以忍受它。
回答by Josh Unger
As others have hinted at, each warning should be addressed separately.
正如其他人所暗示的那样,每个警告都应单独处理。
For your specific warning of -
对于您的具体警告 -
No grammar constraints (DTD or XML schema) detected for the document. TEST-net.kindleit.gae.example.server.MessageRepositoryTest.xml /projecttest-gae-example/target/surefire-reports
I've logged a bug against Surefire as SUREFIRE-964since I'm seeing the same behavior.
我已经将针对 Surefire 的错误记录为SUREFIRE-964,因为我看到了相同的行为。
To exclude only these warnings, you can go to Preferences > Validation. Find XML Validator and click Settings. Select Exclude Group, click Add Rule, select Folder or file name, and click Browser Folder to select target/surefire-reports. At that point, Eclipse should prompt you that you need to rebuild and/or validate. Or, you can right click on your project and select Validate.
要仅排除这些警告,您可以转到首选项 > 验证。找到 XML 验证器并单击设置。选择排除组,单击添加规则,选择文件夹或文件名,然后单击浏览器文件夹以选择目标/surefire-reports。此时,Eclipse 应该提示您需要重建和/或验证。或者,您可以右键单击您的项目并选择验证。
回答by iwan.z
I do not think it is a good idea to turn it off. You might run into issues when you start parsing and so on. It is better to include the DTD in the XML Catalog.
我认为关闭它不是一个好主意。当您开始解析等时,您可能会遇到问题。最好在 XML 目录中包含 DTD。
Go to Windows -> Preferences -> XML -> XML Catalog Add the missing DTD as your user specified entries and eclipse will validate it without any issues. You might need to start the validation of the file afterwards.
转到 Windows -> Preferences -> XML -> XML Catalog 添加缺少的 DTD 作为您的用户指定的条目,eclipse 将对其进行验证而不会出现任何问题。之后您可能需要开始验证文件。
You can find this solution also at http://juliendkim.blogspot.de/2012/09/how-to-fix-log4jdtd-xml-problem-in.htmlwhich describes the issue with a log4j.dtd.
您也可以在http://juliendkim.blogspot.de/2012/09/how-to-fix-log4jdtd-xml-problem-in.html找到此解决方案,其中描述了 log4j.dtd 的问题。