Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9083371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:45:32+00:00 2026-06-16T20:45:32+00:00

I have set up basic maven project in java SE, with a resource: main

  • 0

I have set up basic maven project in java SE, with a resource:

main 
  -java
  -resources
    -config -> database.properties

now since I don’t want this resource in the final jar, I define:

 <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <excludes>
                    <exclude>config/database.properties</exclude>
                </excludes>
            </configuration>
            <executions>
                <execution>
                    <id>make-jar-ultimateParser</id>
                    <phase>package</phase>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/dist</outputDirectory>
                        <finalName>testApp</finalName>
                        <archive>
                            <compress>false</compress>
                            <!-- Manifest - MainClass & ClassPath -->
                            <manifest>
                                <mainClass>aa.bb.Class</mainClass>
                                <addClasspath>true</addClasspath>
                                <classpathPrefix>lib/</classpathPrefix>
                            </manifest>
                            <manifestEntries>
                                <Class-Path>config/database.properties</Class-Path>
                            </manifestEntries>
                        </archive>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <!-- Copy configuration files -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.6</version>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/dist/config</outputDirectory>
                        <resources>
                            <resource>
                                <directory>src/main/resources/config</directory>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.0</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
    </plugins>
</build>

So the resource is on classpath and the directory with the resource is copied to the final jar.

My manifest looks like this: “Class-Path: config/database.properties”

But I’m not able to read it:

String db = "/config/database.properties";
properties = new Properties();
properties.load(getClass().getResourceAsStream(db));

I tried absolute/relative paths, getClass()/ClassLoader. Nothing. It works flawlessly in NetBeans, but that’s about it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T20:45:33+00:00Added an answer on June 16, 2026 at 8:45 pm

    You’re misunderstanding what the Maven Resources plugin does. It simply copies resources (perhaps with transformation) into the build output directory. Where they’re then included into the build artifact (JAR, WAR, whatever).

    To make this work (referencing the JAR’s directory using the Class-Path manifest entry), you need to distribute the config file separately. Or reference it using a File, and not bothering with the classpath.

    A better approach is to distribute your application as an assembly, which contains the core app, any dependencies, and the configuration file. This would typically be packaged as a ZIPfile, and the user would unzip it to install.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have set up a basic client and a basic server using java sockets.
I have a project that includes some Java APIs, some resource files, and some
In IIS 5.1, i have set the website security to Basic Authentications and i
I have a basic messaging system set up and I m using the same
My permalink structure is set so I have url.com/page I made a basic PHP
I have set the eclipse java formatter to wrap lines that exceed 120 characters
I have set of flat files (114 files) each file is named with database
I am having issues with polymorphism I have set these basic classes up methods
I have set up a basic install of XMPPHP and to test it I
I have a set of basic breakpoints defined in a user-defined fn setup in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.