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

  • Home
  • SEARCH
  • 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 3403918
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:19:08+00:00 2026-05-18T05:19:08+00:00

I created a JAR file with my Java program. This piece of code will

  • 0

I created a JAR file with my Java program. This piece of code will open a few files inside a dir “Test”, which is in the same dir as the JAR file. Like this:

/
 -- program.jar
 -- /Test
     -- *

If I run via terminal with: java -jar program.jar, it runs perfectly. But if I run graphically (right clicking on the jar file and Open with OpenJDK…), it doesn’t work properly. Just like if I ran from another directory.

Is it possible that when I run the JAR file graphically it’s running from another directory?

By the way, I’m running on Ubuntu.

  • 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-18T05:19:09+00:00Added an answer on May 18, 2026 at 5:19 am

    Yes, you will get another current working directory… There would be two solutions:

    1) Find the cwd by doing this hack:

        public class Test {
            public static void main(String... args) { 
    
                ClassLoader cl = Test.class.getClassLoader();
                String f = cl.getResource("").getFile();
    
                File cwd = new File(f);
    
                if (cwd.toString().endsWith("!"))
                    cwd = cwd.getParentFile();
    
                JOptionPane.showMessageDialog(null, cwd);
            }
        }
    

    2) If the files under Test are static (does not change to often) the solution would be to package them inside the jar.

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

Sidebar

Related Questions

Is it possible to run a java jar file from within an Oracle (10g)
I created a Java project that contains three configuration file log4j.XML QueueConfig.xml rabbitmq.properties I
I have created a shell script to run a jar file in Mac :
I create jar file with command. $jar -cvf A.jar A.class I tried executing $java
I created a program using dev-cpp and wxwidgets which solves a puzzle. The user
I created a few mediawiki custom tags, using the guide found here http://www.mediawiki.org/wiki/Manual:Tag_extensions I
I created a single page (with code behind .vb) and created Public intFileID As
I know that .jar files are basically archives as well as being applications. What
I'm using the shade Maven2 plugin to build a monolithic JAR with all Java
I created an Interop user control in VS2005. When the user control is shown

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.