【问题标题】:Onejar, with maven, won't copy resource into jarOnejar,带有maven,不会将资源复制到jar中
【发布时间】:2017-08-03 12:46:59
【问题描述】:

我正在使用 one-jar 来打包我的程序。我在 src/main/resources 中有资源。 maven-resources-plugin正确将资源复制到jar中,但是onejar生成的jar中不包含我的资源。

这是我的 pom:

<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>com.ziroby</groupId>
<artifactId>resourceTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>resourceTest</name>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
    <plugins>
        <plugin>
            <groupId>org.dstovall</groupId>
            <artifactId>onejar-maven-plugin</artifactId>
            <version>1.4.4</version>
            <executions>
                <execution>
                    <configuration>
                        <attachToBuild>true</attachToBuild>
                    </configuration>
                    <goals>
                        <goal>one-jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
<pluginRepositories>
    <pluginRepository>
        <id>onejar-maven-plugin.googlecode.com</id>
        <url>http://onejar-maven-plugin.googlecode.com/svn/mavenrepo</url>
    </pluginRepository>
</pluginRepositories>
</project>

我做错了什么?如何在一个 jar 中包含资源?

【问题讨论】:

    标签: maven


    【解决方案1】:

    我发现了我的错误。它把它放在罐子里,只是不是我期望的地方。它包含在主罐子内的罐子中。具体来说,resourceTest-0.0.1-SNAPSHOT.one-jar.jar 包含 resourceTest-0.0.1-SNAPSHOT.jar,其中包含我的资源。

    现在我只需要找出如何访问资源,但这是另一个问题,需要更多研究。

    【讨论】:

    • 您知道如何访问此资源了吗?因为我现在被困在这一点上
    【解决方案2】:

    如果您正在使用类似于以下内容的内容: getClass().getClassLoader().getResourceAsStream

    尝试改用:Thread.currentThread().getContextClassLoader().getResourceAsStream

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-07
      • 1970-01-01
      • 2018-08-24
      • 2017-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多