9

I work with Eclipse, Spring MVC and Maven.The Java version is 1.6

I have the following method

public static DocumentBuilder getBuilder(ServletContext servletContext)
{
 DocumentBuilderFactory factory =DocumentBuilderFactory.newInstance();
        factory.setValidating(true);            

        DocumentBuilder builder = null;
        try {
            factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
            builder = factory.newDocumentBuilder();

I have an error in the eclipse editor in the line:

factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING,

The error is

FEATURE_SECURE_PROCESSING cannot be resolved or not is a field

In the editor Eclipse I see:

enter image description here

Maven dependencies are:

enter image description here

enter image description here

enter image description here

Why don't I have the variable

XMLConstants.FEATURE_SECURE_PROCESSING ?

2 Answers 2

20

I don't know if there is your case, but I solve the problem configuring the source folders in my Java project Build Path, following these steps:

  1. Right click on the project and select "Properties"
  2. Select "Java Build Path" from the left menu
  3. Select "Order and Export" tab
  4. Move "JRE System Library" on Top and Apply

In this way the Java libraries are used before the others.

Sign up to request clarification or add additional context in comments.

Comments

4

One of the libraries in your classpath contains an older version of javax.xml.XMLConstants. You need to find and remove that library. Try using Ctrl + Shift + T or select Navigate -> Open Type in Eclipse to find the offending jar file.

Also, you have at least two libraries, Xerces and Xalan, that aren't necessary and can be removed, as they're bundled with the JDK.

2 Comments

This did not help at all for me
In my case, it was STAX API bundled with Apache POI libs. Used @Ale's solution. This solution should help for excluding jars in pom.xml. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.