1

It's it possible with Maven to share common controllers, jsp's and other resources to the web module.

Structure

web1 (packaging jar)

--main
        --java
            --controller
                MyControllerToShared with @Controller annotation
        --resources
        --webapp
            --scripts
                javascripts files
            --styles
                css files
            --WEB-INF
                --views
                    jsp to share
    pom.xml

web2 (packaging war)

Classic web app structure with dependency of web1.jar

My web2 app works but no mapping found for HTTP request with URI define in web1 module. I use annotation @Controller and @RequestMapping. I defined in the servlet.xml:

<context:component-scan base-package="controller" />
<mvc:annotation-driven/>

How can I share controllers and resources between different web modules? At the end, I need to have 3 web app with commons stuffs (error handler, jsp's errors, styles, js, ...).

evandongen
  • 1,995
  • 17
  • 19
BasicCoder
  • 1,661
  • 10
  • 27
  • 42

2 Answers2

1

Why don't you just create an extra project with all the shared resources? You can reuse that in all your web apps, just include the shared file in your pom.xml as a dependency.

You can start with an additional project with the shared resources:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>nl.connexys</groupId>
    <artifactId>shared</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>Shared resources</name>

</project>

In your webapp project you can then use that project as a dependency:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>nl.connexys</groupId>
    <artifactId>webapp</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>Webservice endpoints</name>

    <dependencies>
        <dependency>
            <groupId>nl.connexys</groupId>
            <artifactId>shared</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>
</project>

But this is all very basic Maven stuff. I think the examples should point you in the right direction.

evandongen
  • 1,995
  • 17
  • 19
  • Now you're just using one project, you need to create a second project and call it 'shared' for instance. I'll edit my answer to add some code examples. – evandongen Feb 04 '13 at 15:15
  • Ok for classes. Already done like your example. But for jsp's? Jsp are not included in the shared.jar. – BasicCoder Feb 04 '13 at 16:29
1

Take a look at this answer: https://stackoverflow.com/a/14143954/600007 , and the refernce for that: http://maven.apache.org/plugins/maven-war-plugin/overlays.html

It will work for jsp-s, js-s, etc...

Community
  • 1
  • 1
zsom
  • 479
  • 1
  • 5
  • 19