Example Project Layout

This is an example project layout that shows one way to organise Tapestry pages, components and tests. Some of this is my personal choice but I'll present everything and you can choose what you like. Note that it assumes the Maven project layout.

 +---src
     +---main
     |   +---java
     |   |   +---myproject
     |   |       +---tapestry
     |   |           +---components
     |   |           |       MyComponent.java
     |   |           |       MyComponent.tml
     |   |           |
     |   |           +---pages    
     |   |           |       MyPage.java
     |   |           |       MyPage.tml
     |   |           |
     |   |           +---services    
     |   |                   AppModule.java
     |   |
     |   +---resources
     |           log4j.properties
     |
     |
     +---test
         +---conf
         |       testng.xml
         |
         +---java
             +---test
                 +---myproject
                     +---tapestry
                         +---components
                         |       MyComponentTest.java
                         |
                         +---demo
                         |   |   DemoModule.java
                         |   |
                         |   +---pages
                         |           MyComponentDemo.tml
                         |           MyComponentDemo.java
                         |
                         +---pages
                         |       MyPageTest.java
                         |
                         +---testsupport
                                 AbstractMyProjectTapestryTest.java
                                 TestInfrastructureModule.java
  • I've put all the component's resources alongside the java class (in src/main/java/myproject/tapestry/components). Personally, I find it much easier to work with resources that are associated with a class if I do this. This is not the default Maven style though.

    To make Maven allow this you need to add the following to your pom (you may need to tweak the 'includes' and 'excludes' rules depending on what you have in your source folders)

    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>false</filtering>
        </resource>
        <resource>
            <directory>src/main/java</directory>
            <excludes>
                <exclude>**/*.java</exclude>
            </excludes>
            <filtering>false</filtering>
        </resource>
    </resources>
    
    <testResources>
        <testResource>
            <directory>src/test/resources</directory>
            <filtering>false</filtering>
        </testResource>
        <testResource>
            <directory>src/test/java</directory>
            <excludes>
                <exclude>**/*.java</exclude>
            </excludes>
            <filtering>false</filtering>
        </testResource>
    </testResources>
    
  • I put all the tests in a parallel package hierarchy prefixed with "test". So the tests for components in myproject.tapestry.components will be found in the package test.myproject.tapestry.components

    This makes it easy to find the tests but also keeps them separate from a Java runtime point-of-view.

    FYI, the Eclipse plugin MoreUnit () makes it easy to jump between classes and tests and understands this convention.

  • Demo pages for testing components go in a demo package alongside the components package containing the tests.