开发者

eclipse on maven project warning 'DTD or XML schema'

开发者 https://www.devze.com 2022-12-15 15:59 出处:网络
Description ResourcePathLocationType No grammar constraints (DTD or XML schema) detected for the document.TEST-net.kindleit.gae.example.server.MessageRepositoryTest.xml/projecttest-gae-example/target/
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?

example 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" 开发者_JAVA百科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>


Initial answer (Dec. 2009)

If you have WTP (with the XML part included):

Preferences->Validation->XML Validator-> unclick manual and/or build should prevent eclipse checking the 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 add build.xml to the exclude filter if you would still like this warning for other XML files.

eclipse on maven project warning 'DTD or XML schema'


Update (Feb. 2012)

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:

  1. with Log4j.xml file, saying it cannot find the XML definition for log4j.dtd although the file is in the system path where the Validator looks
  2. Ant build.xml file says I have no grammar constraints
  3. for some reason I can't clean the project.

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 331749 complains about "No grammar constraints" even though directory is excluded

Obviously, more fixes are required regarding the management of those warnings.


How to fix the above problem on 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).

Is it because I miss out some dtd files?

No, it's because the XML document doesn't declare any DTD or 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.


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-964 since I'm seeing the same behavior.

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.


It's just a warning. In preferences: XML/XML Files/Validation, you can turn it off.


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.

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.

You can find this solution also at http://juliendkim.blogspot.de/2012/09/how-to-fix-log4jdtd-xml-problem-in.html which describes the issue with a log4j.dtd.

0

精彩评论

暂无评论...
验证码 换一张
取 消