标签: maven-resources-plugin

Maven:如何将资源文件与jar一起放置?

我有\ src\main\resources\logback.xml文件.当我运行mvn package它时默认放入jar.我怎样让Maven把它放在罐子旁边,而不是放在里面?

所以,好吧,我只是想让Maven将资源复制到jar所在的文件夹中.

maven maven-resources-plugin

29
推荐指数
1
解决办法
4万
查看次数

使用Maven资源保留文件的权限:testResources

是否可以使用Maven资源保留文件的权限:testResources?我的用例是一个Selenium二进制驱动程序,我放在/ src/test/resources中,我希望能够在我的测试中使用它.然而,我的-rwxr-xr-x在目标/测试类中变为-rw-r - r--

file-permissions maven maven-resources-plugin

27
推荐指数
1
解决办法
1万
查看次数

如何过滤maven中的测试资源?

我有以下内容pom.xml.当我运行时mvn clean resources:testResources,我的测试资源没有被过滤(在将资源中的占位符以其修改后的形式放入输出文件夹之前替换它们).为什么?

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>foo</artifactId>
    <version>0.0.1</version>
    <packaging>jar</packaging>
    <name>foo</name>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <resources>
            <resource>
                <directory>src/test/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>
</project>
Run Code Online (Sandbox Code Playgroud)

maven maven-resources-plugin

24
推荐指数
1
解决办法
1万
查看次数

使用copy-resources目标的maven-resources-plugin错误:'resources','outputDirectory'缺失或无效

我正在尝试使用maven-resources-plugin使用copy-resources目标进行一些过滤,并遇到以下错误:

Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.5:copy-resources (default-cli) on project bar: The parameters 'resources', 'outputDirectory' for goal org.apache.maven.plugins:maven-resources-plugin:2.5:copy-resources are missing or invalid
Run Code Online (Sandbox Code Playgroud)

为了隔离这个问题,我创建了一个非常简单的pom.xml,几乎从http://maven.apache.org/plugins/maven-resources-plugin/examples/copy-resources.html中逐字复制,运行它,并得到了同样的错误.

我正在调用它

mvn resources:copy-resources
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?这是测试pom.xml.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>foo</groupId>
  <artifactId>bar</artifactId>
  <version>1.0-SNAPSHOT</version>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.5</version>
        <executions>
          <execution>
            <id>copy-resources</id>
            <!-- here the phase you need -->
            <phase>validate</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${basedir}/target/extra-resources</outputDirectory>
              <resources>          
                <resource>
                  <directory>src/non-packaged-resources</directory>
                  <filtering>true</filtering>
                </resource>
              </resources>              
            </configuration>            
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
Run Code Online (Sandbox Code Playgroud)

maven maven-resources-plugin

17
推荐指数
2
解决办法
3万
查看次数

.gitignore文件未复制到原型JAR - 变通办法?

目前在maven-resources-plugin中存在一个错误,即.gitignore文件未复制到原型JAR.请参阅此错误报告

简短而简单的问题:在原型中获取文件有变通方法吗?

编辑:行家资源插件版本设置为2.6并没有解决我的问题(如提到这里)

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.6</version>
            </plugin>
        </plugins>
    </pluginManagement>
</build>
Run Code Online (Sandbox Code Playgroud)

gitignore maven maven-resources-plugin maven-archetype

17
推荐指数
1
解决办法
2706
查看次数

Maven随机不会过滤资源

这有点令人发狂,我在Maven工作几年之前从未见过它.一个简单的项目(我自己没有写过)会随机地过滤资源,我无法弄清楚可能导致它的原因.我不能分享项目源代码,但我会尝试尽可能多地分享POM.请记住,问题不在于代码,而是Maven随机决定不过滤资源.

我最初在我的POM的构建标记中配置了这个:

<resources>
  <resource>
    <directory>src/main/resources</directory>
    <filtering>true</filtering>
  </resource>
</resources>
Run Code Online (Sandbox Code Playgroud)

在我的src/main/resources目录中,我有一个名为spring-config.xml的文件.此文件中有几个属性,应由Maven配置文件属性替换.我已经配置了我的构建配置文件:

<profile>
  <id>stage</id>
  <properties>
    <env.name>STAGE</env.name>
    <db.url>jdbc:oracle:thin:@xxx.xxx.com:1521:xxx</db.url>
  </properties>
</profile>
Run Code Online (Sandbox Code Playgroud)

要构建,我运行此命令:

mvn clean package -P stage
Run Code Online (Sandbox Code Playgroud)

现在,这个项目使用Spring,它使用相同的Spring配置进行测试和执行,因此上下文将在运行测试用例时创建数据库连接.大多数情况下,构建将完成,测试用例将通过.但是,在10中大约有1次,测试用例将失败,因为属性没有被替换,Spring尝试连接到"$ {db.url}"而不是"jdbc:oracle:thin:@ xxx.xxx.com:1521 :XXX".

奇怪的是,尽管刚刚通过测试案例,但打包的JAR在10中大约有9次会遇到同样的问题.我检查了目标/ classes目录,那里的文件有完全相同的问题.我认为在构建生命周期的某个点上使用Maven资源插件会发生奇怪的事情,也许它会错误地覆盖文件.

我的绑带解决方案

在Maven生命周期中,顺序是compile-> test-> package.因此,为了在令我头疼的两个阶段上强制过滤资源,我将资源插件配置为在编译阶段和测试阶段运行:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.6</version>
    <configuration>
      <encoding>UTF-8</encoding>
    </configuration>
    <executions>
      <execution>
        <id>this-is-silly</id>
        <phase>compile</phase>
        <goals>
          <goal>resources</goal>
        </goals>
      </execution>
      <execution>
        <id>why-must-i-exist</id>
        <phase>test</phase>
        <goals>
          <goal>resources</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
Run Code Online (Sandbox Code Playgroud)

这似乎是一贯的工作,但我仍然没有任何世俗的想法,为什么我需要在过去几年中为数十个项目中的一个项目做这个.我以前从未见过Maven间歇性地做某事,这让我担心它会再次破裂.任何想法将不胜感激.

java maven-3 maven maven-resources-plugin

9
推荐指数
1
解决办法
804
查看次数

Maven:添加外部资源

我正在用maven构建一个可执行jar文件,这意味着你用"java -jar file.jar"运行它.

我想依赖于用户定义的属性(只是一个包含键/值的文件),在开发阶段我将我的"user.properties"文件放在maven/src/main/resources /文件夹中.

我的属性文件加载了:

final Properties p = new Properties();
final InputStream resource = IOParametres.class.getResourceAsStream("/user.properties");
p.load(resource);
Run Code Online (Sandbox Code Playgroud)

现在,我想将该文件保留在JAR之外,并且具有以下内容:

- execution_folder
   |_ file.jar
   |_ config
      |_ user.properties
Run Code Online (Sandbox Code Playgroud)

我用maven插件尝试了很多东西,比如maven-jar-plugin,maven-surefire-plugin和maven-resources-plugin,但是我无法让它工作......

在此先感谢您的帮助!

java jar maven maven-jar-plugin maven-resources-plugin

9
推荐指数
1
解决办法
2万
查看次数

Apache Maven 资源插件排除目录

我试图在构建过程中将一些资源从一个点复制到另一个点。因此我使用 Apache Maven 资源插件。其实我排除了一些文件,我不需要。但我也想排除一个目录。我尝试了几种方法,但没有奏效。

<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
    <execution>
        <id>copy-client-product</id>
        <phase>verify</phase>
        <goals>
            <goal>copy-resources</goal>
        </goals>
        <configuration>
            <outputDirectory>${basedir}/target/pro/client</outputDirectory>
            <resources>
                <resource>
                    <directory>target\products\client\win32\win32\x86\</directory>
                    <excludes>
                        <exclude>p2</exclude>
                        <exclude>eclipsec.exe</exclude>
                    </excludes>
                </resource>
            </resources>
        </configuration>
    </execution>
</executions>
Run Code Online (Sandbox Code Playgroud)

在这个例子中,我试图排除文件夹“p2”。

<exclude>*/p2/**</exclude>
<exclude>p2/**</exclude>
<exclude>**/p2</exclude>
Run Code Online (Sandbox Code Playgroud)

也不行。

maven maven-resources-plugin

8
推荐指数
1
解决办法
1万
查看次数

使用配置文件属性进行Maven资源过滤

我有以下pom.xml:

<project
    xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>mycompany</groupId>
    <artifactId>resource-fail</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <properties>
        <foo.bar>BazBat</foo.bar>
    </properties>
    <build>
        <resources>
            <resource>
                <filtering>true</filtering>
                <directory>src/main/resources</directory>
            </resource>
        </resources>
    </build>
    <profiles>
        <profile>
            <id>Development</id>
            <!--
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            -->
            <properties>
                <foo.bar>Development</foo.bar>
            </properties>
        </profile>
    </profiles>
</project>
Run Code Online (Sandbox Code Playgroud)

请注意,该activation元素已profile被注释掉

我也有以下内容 src/main/java/application.properties

myproperty=${foo.bar}
Run Code Online (Sandbox Code Playgroud)

因此,我希望Maven的做的仅仅是更换${foo.bar}BazBat,除非发展轮廓activiated,那么我期待Maven来代替${foo.bar}Development

当我运行mvn package它时,将值设置为BazBat.好,资源过滤按预期工作.

但是,当我运行mvn package -P Development它时,将值设置为BazBat

为了进一步混淆,如果取消注释activation配置文件中的元素并运行mvn package它将设置${foo.bar}Development

我甚mvn help:active-profiles package至跑来让它输出活动的配置文件名称,并且在上面的两个场景中它都说开发配置文件是活动的,但是如果没有activeByDefault设置标志,过滤仍然不起作用. …

maven maven-resources-plugin maven-profiles

8
推荐指数
1
解决办法
2068
查看次数

使用资源过滤时如何在Eclipse中的pom.xml上忽略丢失的过滤器文件错误?

我有一个这样的多模块项目:

parent
|
+-- childA
|   +-- src/main/resources/application.properties
|
+-- childB
    +-- src/main/resources/application.properties
    +-- src/main/filters/filter.properties
Run Code Online (Sandbox Code Playgroud)

application.properties使用filter.propertiesin childB 过滤了childA和childB.

我遵循这个策略将过滤器文件附加到childB的工件,然后将其解压缩到childA的目标上:

childA/target/filters/filter.properties
Run Code Online (Sandbox Code Playgroud)

childA有这样的资源过滤:

<build>
  <filters>
    <filter>target/filters/filter.properties</filter>
  </filters>
</build>
Run Code Online (Sandbox Code Playgroud)

Eclipse正在标记错误childA/pom.xml:

加载属性文件'parent\childA\target\filters\filter.properties'时出错(org.apache.maven.plugins:maven-resources-plugin:3.0.2:copy-resources:default-resources:process-resources)

我构建应用程序时可以使用过滤器文件,因此我并不担心.

如何更新childA的pom.xml以永久忽略此错误?

java eclipse maven-3 maven maven-resources-plugin

8
推荐指数
1
解决办法
957
查看次数