1

I have a project that has resources inside the same package as some java classes.

The project structure is something like:

src
    main
        java
            nl
                project
                    someTitle.java
                    someTitle.css

In my pom.xml I have included the following snippet:

<resources>
    <resource>
        <directory>src</directory>
        <excludes>
             <exclude>**/*.class</exclude>
        </excludes>
    </resource>
</resources>

When I do a [mvn clean verify] the .css-file does not get included in my war package. How come?

4
  • 3
    use src/main/resources for that. It will be autoincluded from there. Maven filters src/main/java for non-java files. Commented Oct 17, 2017 at 12:23
  • You should not have any resources under /src/main/java. Resources should be under /src/main/resources Commented Oct 17, 2017 at 12:23
  • I know this would be best practice, but due to legacy code I have to put it in the same package as the class... Commented Oct 17, 2017 at 12:33
  • 1
    Not relevant to the question, but... It is also weird to have class files in your source directory. Commented Oct 17, 2017 at 12:35

2 Answers 2

1

You can put files in the same package as the class, and still put the files in src/main/resources as suggested. Same package does not necessarily mean same directory.

So:

src
    main
        resources
            nl
                project
                    someTitle.css

The default Maven lifecycle will take it from there.

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

Comments

0

Add this in resources section:

 <resources>
        <resource>
            <directory>src/main/java</directory> 
            <includes>
                 <include>**/*.css</include> 
            </includes>
        </resource>
</resources>

1 Comment

You should add some text around your answer to explain the code.

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.