从JavaMaven构建中排除资源

从JavaMaven构建中排除资源,java,eclipse,maven,jar,Java,Eclipse,Maven,Jar,似乎有很多关于类似问题的帖子,但我一直找不到确切的答案 基本上,我在Eclipse中使用Maven构建了一个Java应用程序。当我使用Eclipse执行项目时,它工作正常,因为它可以在我的资源目录中找到所有文件。当我使用maven构建带有依赖项的普通jar时,它也可以工作。但是,在最后一项中,我无法实现这一点: 我希望将资源从主可执行jar中排除,并放置到与jar本身相同级别的目录中。这是一个用户可以对设置进行更改并执行jar,因此: |--root level |-Jar |-resour

似乎有很多关于类似问题的帖子,但我一直找不到确切的答案

基本上,我在Eclipse中使用Maven构建了一个Java应用程序。当我使用Eclipse执行项目时,它工作正常,因为它可以在我的资源目录中找到所有文件。当我使用maven构建带有依赖项的普通jar时,它也可以工作。但是,在最后一项中,我无法实现这一点:

我希望将资源从主可执行jar中排除,并放置到与jar本身相同级别的目录中。这是一个用户可以对设置进行更改并执行jar,因此:

|--root level
 |-Jar
 |-resources
  |-log4j.properties
  |-settings.properties
我让maven jar插件执行以下操作:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.4</version>
    <configuration>
        <archive>
        <index>true</index>
        <manifest>
            <addClasspath>true</addClasspath>
            <mainClass>com.org.interfaces.SharepointClient.App</mainClass>
            <classpathPrefix>lib/</classpathPrefix>
        </manifest>
        <manifestEntries>
            <mode>development</mode>
            <url>http://org.com</url>
            <key>value</key>
            <Class-Path>resources/settings.properties resources/log4j.properties</Class-Path>
        </manifestEntries>
        </archive>
        <excludes>
            <exclude>settings.properties</exclude>
            <exclude>log4j.properties</exclude>
        </excludes>
    </configuration>
</plugin>
执行时,我在这行代码上收到一个错误: PropertyLoader.class.getClassLoader().getResourceAsStream(“settings.properties”)

错误是:

Exception in thread "main" java.lang.NullPointerException
    at java.util.Properties$LineReader.readLine(Unknown Source)
    at java.util.Properties.load0(Unknown Source)
    at java.util.Properties.load(Unknown Source)
    at com.org.interfaces.SharepointClient.PropertyLoader.getProps(PropertyLoader.java:29)
编辑:
我只是在让java加载资源而不是依赖项方面遇到了麻烦。这些似乎加载正确。

我认为您使这项工作变得更加困难。看看这个。您只需将所有依赖项添加到pom.xml文件中即可。这样,无论何时传输代码,maven都将使用pom.xml文件来重建包含所有依赖项的项目。让它变得更容易。您所要做的就是在存储库中搜索依赖项,并将其复制到pom文件中。

感谢您的回复,但问题不在于依赖项。我让maven根据说明获取依赖项。我很难在类路径上获取资源,如属性文件,但它们没有与主jar文件捆绑在一起。您是否尝试在类路径中仅包含“resources/”?我尝试过,但似乎没有任何内容包含这些资源。这就像类路径被某个东西覆盖了一样。为了验证类路径,请检查java应用程序中'System.getProperty(“java.class.path”)`的值是多少。您还可以尝试使用
getsystemresourceastream(字符串名称)
Exception in thread "main" java.lang.NullPointerException
    at java.util.Properties$LineReader.readLine(Unknown Source)
    at java.util.Properties.load0(Unknown Source)
    at java.util.Properties.load(Unknown Source)
    at com.org.interfaces.SharepointClient.PropertyLoader.getProps(PropertyLoader.java:29)