javaeclipseejb-3.1ejb-jar.xml

Eclipse marks ejb-jar.xml entry <ejb-class> as invalid


I'm on a legacy EJB project using Eclipse with the following ejb-jar.xml:

<ejb-jar version="3.1" xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd">
  <display-name>Verwaltung</display-name>
  <enterprise-beans>
    <session>
      <description>EJB für den Zugriff auf die Configuration</description>
      <ejb-name>EnvironmentEntries</ejb-name>
      <init-on-startup>true</init-on-startup>
      <ejb-class>
        some.package.name.EnvironmentEntries
      </ejb-class>
      <session-type>Singleton</session-type>
    </session>
  </enterprise-beans>
</ejb-jar>

Gives an error:

cvc-complex-type.2.4.a: Invalid content was found starting with element 'ejb-class'. One of '{
"http://java.sun.com/xml/ns/javaee":concurrency-management-type,
"http://java.sun.com/xml/ns/javaee":concurrent-method, 
"http://java.sun.com/xml/ns/javaee":depends-on,
"http://java.sun.com/xml/ns/javaee":init-method,
"http://java.sun.com/xml/ns/javaee":remove-method,
"http://java.sun.com/xml/ns/javaee":async-method,
"http://java.sun.com/xml/ns/javaee":transaction-type,
"http://java.sun.com/xml/ns/javaee":after-begin-method,
"http://java.sun.com/xml/ns/javaee":before-completion-method,
"http://java.sun.com/xml/ns/javaee":after-completion-method,
"http://java.sun.com/xml/ns/javaee":around-invoke,
"http://java.sun.com/xml/ns/javaee":around-timeout,
"http://java.sun.com/xml/ns/javaee":env-entry,
"http://java.sun.com/xml/ns/javaee":ejb-ref,
"http://java.sun.com/xml/ns/javaee":ejb-local-ref,
"http://java.sun.com/xml/ns/javaee":service-ref,
"http://java.sun.com/xml/ns/javaee":resource-ref,
"http://java.sun.com/xml/ns/javaee":resource-env-ref,
"http://java.sun.com/xml/ns/javaee":message-destination-ref,
"http://java.sun.com/xml/ns/javaee":persistence-context-ref,
"http://java.sun.com/xml/ns/javaee":persistence-unit-ref,
"http://java.sun.com/xml/ns/javaee":post-construct,
"http://java.sun.com/xml/ns/javaee":pre-destroy,
"http://java.sun.com/xml/ns/javaee":data-source,
"http://java.sun.com/xml/ns/javaee":post-activate,
"http://java.sun.com/xml/ns/javaee":pre-passivate,
 http://java.sun.com/xml/ns/javaee":security-role-ref,
"http://java.sun.com/xml/ns/javaee":security-identity}
' is expected.

Screenshot:

enter image description here

I'm not very good at reading XSD files, but according to https://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd and the official TomEE docs https://tomee.apache.org/examples-trunk/simple-stateless-with-descriptor/ this seems to be fine.

Q:

What's wrong?

Is Eclipse doing some weird validation here (again)? How do you fix or get rid of this?

EDIT:

Suspending all validators in Eclipse doesn't work:

enter image description here


Solution

  • The message says that the order of the elements matters. Hover over the session tag name to see the content model, where the parentheses not being followed by a + or * indicates a strict order.

    It should be:

    <ejb-jar version="3.1" xmlns="http://java.sun.com/xml/ns/javaee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd">
      <display-name>Verwaltung</display-name>
      <enterprise-beans>
        <session>
          <description>EJB für den Zugriff auf die Configuration</description>
          <ejb-name>EnvironmentEntries</ejb-name>
          <ejb-class>
            some.package.name.EnvironmentEntries
          </ejb-class>
          <session-type>Singleton</session-type>
          <init-on-startup>true</init-on-startup>
        </session>
      </enterprise-beans>
    </ejb-jar>
    

    Servers probably don't care whether the order is correct, but the schema is the schema.