Making maven copy additional files inside the build jar (not resources but any file inside any package)?

后端 未结 3 1704
深忆病人
深忆病人 2020-12-18 04:21

I have a package org.myapp.mypackage with some ruby files (*.rb) and I need to include them in the generated build jar in the same package

相关标签:
3条回答
  • 2020-12-18 04:32

    Not sure if i understood the problem correctly, but if your Ruby files are packaged by maven and declared as a dependency, you can use the shade plugin to include the contents into the resulting jar file:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>1.4</version>
        <executions>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>shade</goal>
                </goals>
                <configuration>
                    <artifactSet>
                        <includes>
                            <include>org.myapp.mypackage:mypackage</include>
                        </includes>
                    </artifactSet>
                    <filters>
                        <filter>
                            <artifact>org.myapp.mypackage:mypackage</artifact>
                            <includes>
                                <include>org/my/package/*.rb</include>
                            </includes>
                        </filter>
                    </filters>
                </configuration>
            </execution>
        </executions>
    </plugin>
    
    0 讨论(0)
  • 2020-12-18 04:50

    You can modify the resources section of the <build> bit of the POM:

    <resources>
      <resource>
        <directory>src/main/resources</directory>
      </resource>
      <resource>
        <filtering>false</filtering>
        <directory>src/main/java</directory>
        <includes>
          <include>*.rb</include>
        </includes>
        <excludes>
          <exclude>**/*.java</exclude>
        </excludes>
      </resource>
    </resources>
    

    Or, the other answer (create the same package structure in src/main/resources) will also work.

    0 讨论(0)
  • 2020-12-18 04:52

    Put them in the correct directory (src/main/resources in general) and they should be bundled into the Jar properly. To put you *.rb files create the same dir structure under the src/main/resources folder.

    0 讨论(0)
提交回复
热议问题