简体   繁体   English

maven-jar-plugin文件过滤器

[英]maven-jar-plugin file filterring

I have a some perl file in my src/main/java/com/pac/report.pl which I want to package as part of my classes in the jar file. 我在src/main/java/com/pac/report.pl中有一些perl文件,我想在jar文件中打包作为我的类的一部分。

Using maven maven-jar-plugin include directives, I have tried below and various other suggestions I pulled off the web, but doesn't copy the perl file as part of my classes in the jar file. 使用maven maven-jar-plugin包含指令,我在下面尝试了以及我从网上下载的各种其他建议,但是没有将perl文件作为我的类的一部分复制到jar文件中。 Does anyone know what I am doing wrong. 有谁知道我做错了什么。

<plugin>
 <artifactId>maven-jar-plugin</artifactId>
 <version>2.4</version>
  <configuration>
    <includes>
     <include>**/*</include>
     </includes>
  </configuration>
 </plugin>

EDIT 编辑

Also let me point out that I don't want to place the file in the resource directory due to legacy call and dependent reasons. 另外,我要指出,由于遗留呼叫和相关原因,我不希望将文件放在资源目录中。

That is because the classes packaged into your jar aren't taken from src , but rather from target (specifically /target/classes ), and the compiler completely ignores your non-java file. 这是因为打包到jar中的类不是从src中获取的 ,而是来自目标(特别是/target/classes ),编译器完全忽略了你的非java文件。

Try placing your file in src/main/resources/com/pac/report.pl and it should be packaged into the jar (with the relative path of /com/pac/report.pl ) since thats the default location where the resources plugin looks for additional files to add to /target before the jar plugin runs. 尝试将您的文件放在src/main/resources/com/pac/report.pl ,它应该打包到jar中(使用/com/pac/report.pl的相对路径),因为那是资源插件的默认位置在jar插件运行之前查找要添加到/ target的其他文件。

EDIT - or, if you dont want to / cant do this the way maven expects, you could manually bind an execution of the resources plugin to the lifecycle to pick up your file and copy it over to target. 编辑 - 或者,如果您不希望/不能像maven所期望的那样执行此操作,您可以手动将资源插件的执行绑定到生命周期以获取文件并将其复制到目标。 something like this: 这样的事情:

<build>
    <plugins>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.6</version>
        <executions>
          <execution>
            <id>copy-resources</id>
            <phase>compile</phase> <!-- or later -->
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${basedir}/target/classes</outputDirectory>
              <resources>          
                <resource>
                  <!-- path to your *.pl file here -->
                </resource>
              </resources>              
            </configuration>            
          </execution>
        </executions>
      </plugin>
    </plugins>
    ...
  </build>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM