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

The Archive Base Latest Questions

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

Similar to this question, I’d like to know how to get the current jar

  • 0

Similar to this question, I’d like to know how to get the current jar file’s path. But unlike the other question, I want to know the jar‘s path, not the path of the current file inside the jar. For example, say I had a jruby jar at “/Users/MyUser/Jars/foo.jar” and inside was a compiled ruby file at “foo.jar/java/style/class/path.class”. How could class.path get the path “/Users/MyUser/Jars/foo.jar”?

I also saw a way to do it in Java, but I just don’t know how to translate 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-05-31T10:48:18+00:00Added an answer on May 31, 2026 at 10:48 am

    I have experimented with this a bit, and any attempt to call the code from JRuby returns the jruby jar itself, which kind of makes sense as the logic is indeed evaluated/executed from that jar. For instance:

    require 'java'
    puts self.to_java.get_class().protection_domain().code_source().location().path()
    

    or

    require 'java'
    
    class Path
      def get_jar_path
        self.to_java.get_class().protection_domain().code_source().location().path()
      end
    end
    
    puts Path.new.get_jar_path
    

    both return the path to jruby-complete.jar, which can be useful to some extent but apparently not what you’re looking for.

    The only way I could get this to work (with rawr, but this can be easily adapted if you use warbler) is to create a Java class in src/java/org/rubyforge/rawr:

    package org.rubyforge.rawr;
    
    public class Path {
      public String getJarPath() {
        return getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
      }
    }
    

    Then call this class from the JRuby script:

    require 'java'
    java_import 'org.rubyforge.rawr.Path'
    
    puts Path.new.get_jar_path
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Similar to this question , I would like to play a WAV file in
Similar to this question . I would like to find all commented files. But
Similar to this question , but taking it a step further. I would like
Similar to this question , I would like to know how to generate all
Similar to this question about NSubstitute , I want to know if one is
Similar to This Question using linq to SQL , but I don't want to
Similar to this question: How to get the last path in a URL? ...Except
Similar to this question only the other way of flow. Insert Picture into SQL
This question is similar to this one, but with an extra wrinkle: Auto-removing all
This question is similar to this other one , with the difference that the

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.