Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add generated build file to classpath

Tags:

java

maven-2

During my build I generate a build.properties files via the maven properties plugin (properties-maven-plugin) containing build information.

What's the best way to have this file included in the generated jar? I don't want to put it into the src/main/resources directory as this would pollute my default resource directory.

Is there not a "generated-resources" directory as there is with source?

like image 688
Michael Wiles Avatar asked Feb 15 '12 11:02

Michael Wiles


People also ask

How does maven create the classpath?

Maven creates this classpath by considering the project's dependencies. The reported classpath consists of references to JAR files cached in local Maven repository. Even the JAR artifact of the project is referenced from local Maven cache and not from the /target directory one or the other might expect.

What does Maven generate sources do?

The “maven-source” plugin is used to pack your source code and deploy along with your project. This is extremely useful, for developers who use your deployed project and also want to attach your source code for debugging.


2 Answers

I thought there was a default generated-resources directory, but I can't find any documentation on that at the moment. You can always configure additional resource directories in your pom:

<build>
    <resources>
        <resource>
            <directory>${basedir}/src/main/resources</directory>
        </resource>
        <resource>
            <directory>${project.build.directory}/generated-resources</directory>
        </resource>
    </resources>
    ...
</build>
like image 120
Jörn Horstmann Avatar answered Nov 15 '22 12:11

Jörn Horstmann


Place generated sources in target/generated-sources

There is a plugin called build-helper that allows you to add that folder to the source-folders list.

like image 41
wemu Avatar answered Nov 15 '22 12:11

wemu