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 1037113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:48:52+00:00 2026-05-16T14:48:52+00:00

The question says it all. The specialty in my case is that the current

  • 0

The question says it all.

The specialty in my case is that the current working directory is not the location of the jar file but c:\Windows\system32 (My jar file is started by windows using the right-click-menu, i want to pass a folder’s path as a parameter to the jar).

Now I want to load a configuration file called config.xml that is in the same folder as the jar. The purpose of the file is, of course, to provide settings for the jar. It is important for me that the xml file is outside of the jar file for easy editing.

I’m having a hard time loading that file. Windows executes the line

cmd /k java -jar D:\pathToJarfile\unpacker-0.0.1-SNAPSHOT-jar-with-dependencies.jar

Calling the whole thing with cmd /k leaves the windows command prompt open so that I can see the jar’s output.

I cannot use new File(".") or System.getProperty("user.dir") for the relative path as these functions return C:\Windows\system32\. and C:\Windows\system32, respectively (which is the working folder for everything that windows executes AFAIK).

I’ve had no success with Launcher.class.getResourceAsStream("/../config.xml") either. Since that path begins with /, searching starts at the root node of the jar. Going to ../config.xml point exactly to that file, but the call returns null.

Can someone point me in the right direction? I’m really stuck here. This file loading stuff really bugs me everytime…

Requirements by myself:

  • I don’t want to hardcode the path in the java source code
  • I don’t want to pass the file’s path as a parameter to the java -jar call (neither as a param to the main(String[] args) nor using -Dpath=d:\... to set a system property)

In addition to the original problem, I had a hard time to have maven2 place Class-Path: . into the MANIFEST.MF (The solution that BalusC posted) when using jar-with-dependencies.
The problem was that the line appeared in the regular jar’s MANIFEST file, but not the jar-with-dependencies.jar’s MANIFEST file (2 jar files are generated).
For anyone who cares how i did it:

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.2-beta-5</version>
    <configuration>
      <archive>
        <manifest>
          <mainClass>${mainClass}</mainClass>
          <addClasspath>true</addClasspath>
          <!--at first, i tried to place the Class-Path entry
              right here using <manifestEntries>. see below -->
        </manifest>
      </archive>
      <descriptorRefs>
        <descriptorRef>jar-with-dependencies</descriptorRef>
      </descriptorRefs>
    </configuration>
    <executions>
      <execution>
        <goals>
          <goal>attached</goal>
        </goals>
        <phase>package</phase>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
          <archive>
            <manifest>
              <mainClass>${mainClass}</mainClass>
            </manifest>
            <!--this is the correct placement -->
            <manifestEntries>
              <Class-Path>.</Class-Path>
            </manifestEntries>
          </archive>
        </configuration>
      </execution>
    </executions>
  </plugin>
  • 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-05-16T14:48:53+00:00Added an answer on May 16, 2026 at 2:48 pm

    To get Launcher.class.getResourceAsStream("/../config.xml") to work, you need to add its path to the Class-Path entry of the JAR’s MANIFEST.MF file. This is the normal practice.

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

Sidebar

Related Questions

Question says it all. I tried browsing through the latest tag but could not
Question says it all, I've got a 500,000 line file that gets generated as
Question says it all - is there a class somewhere in Windows Forms that
Question says it all. Working with an old codebase that is using NHibernate 1.2.
The question says it all. I am looking for a build.xml file browser where
The question says it all. I understand that VC11 is currently only in beta,
Question says it all, really. I'm not sure what the problem is. I'm fairly
Question says it all. Is there a way to enforce case sensitivity in VB.Net
Question says it all. I want C function call that returns the list the
Question says it all. Any help with working sample much appreciated. Thanks.

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.