Mutant Bob
Mutant Bob

Reputation: 3549

How do I specify a directory prefix on a set of resources in maven's pom.xml

I have a set of files I'd like to include in the .jar generated by mvn compile. Unfortunately, I would like them to be placed in a specific path inside the .jar. For example, I want shaders/main.glsl to be in the .jar file as com/purplefrog/expglsl/castle/main.glsl

How do I specify this mapping in the pom.xml ? I can not mess with the directory heirarchy of the source project without throwing a wrench into other coders' workflows.

Upvotes: 0

Views: 599

Answers (2)

Robert Scholte
Robert Scholte

Reputation: 12335

During the process-resources phase non-compilable files can be moved (by the maven-resources-plugin). What you should do is add a resource-block to your pom. Here you need to specify the directory. You can also add a targetPath. All together it would look like

<resource>
  <directory>shaders</directory>
  <!-- include all ore just a couple of files? -- >
  <includes>
    <include>main.glsl</include>
  </includes>
  <targetPath>com/purplefrog/expglsl/castle</targetPath>
</resource> 

Now these files are copied to the target/classes and during the package phase they'll become part of the jar.

Upvotes: 1

whitlaaa
whitlaaa

Reputation: 922

Take a look at the Maven Resources Plugin and this question.

Sounds like that should handle what you're looking to do if modifying the project structure up front isn't an option.

Upvotes: 1

Related Questions