Search code examples
eclipsejspdependenciestomcat7

Eclipse JSP in dependency project without Maven


I have the following setup:

Project A - A Dynamic Web project, which depends on project B. Project B - A Dynamic Web project, that defines a Test.jsp file.

If I launch project B on the server, or move the Test.jsp to project A and launch project A on the server. it works just fine, and I can access the .../Test page'.

But when the Test.jsp remains in project B and I launch project A, although I do see the project-b.jar in the war file and the classes from project B does load, which means most of the process works ok, and only the jsps are not added...

How can I solve this?


Solution

  • In Case anyone would get to this question, the solution described in here works well, though was not very clear at first:

    In my project B, place your jsp files so:

    src/main/webapp/META-INF/resources/${path-to-jsp}/file.jsp
    

    In src/main/webapp/META-INF/ create a web-fragment.xml with your variation of the following content:

    <web-fragment
        metadata-complete="true"
        version="3.0"
        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/web-fragment_3_0.xsd">
    
        <servlet>
            <servlet-name>jspTest</servlet-name>
            <jsp-file>/${path-to-jsp}/file.jsp</jsp-file>
        </servlet>
        <servlet-mapping>
            <servlet-name>jspTest</servlet-name>
            <url-pattern>/test</url-pattern>
        </servlet-mapping>
    </web-fragment>
    

    and now if your buildpath is defined correctly, then clean-build both project B, and project A and run the server again... it works!