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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:29:51+00:00 2026-06-13T01:29:51+00:00

In clojure.java.io , there is a io/resource function but I think it just loads

  • 0

In clojure.java.io, there is a io/resource function but I think it just loads the resource of the current jar that is running. Is there a way to specify the .jar file that the resource is in?

For example:

  • I have a jar file: /path/to/abc.jar
  • abc.jar when unzipped contains some/text/output.txt in the root of the unzipped directory
  • output.txt contains the string "The required text that I want."

I need functions that can do these operations:

(list-jar "/path/to/abc.jar" "some/text/")
;; => "output.txt"

(read-from-jar "/path/to/abc.jar" "some/text/output.txt")
;; => "The required text that I want"

Thanks in advance!

  • 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-13T01:29:52+00:00Added an answer on June 13, 2026 at 1:29 am

    From Ankur’s comments, I managed to piece together the functions that I needed:

    The java.util.jar.JarFile object does the job.

    you can call the method (.entries (Jarfile. a-path)) to give the list of files but instead of returning a tree structure:

    i.e:

    /dir-1
      /file-1
      /file-2
      /dir-2
        /file-3
      /dir-3
        /file-4
    

    it returns an enumeration of filenames:

    /dir-1/file-1, /dir-1/file-2, /dir-1/dir-2/file-3, /dir-1/dir-3/file-4

    The following functions I needed are defined below:

    (import java.util.jar.JarFile)
    (defn list-jar [jar-path inner-dir]
      (if-let [jar          (JarFile. jar-path)]
        (let [inner-dir    (if (and (not= "" inner-dir) (not= "/" (last inner-dir)))
                             (str inner-dir "/")
                             inner-dir)
              entries      (enumeration-seq (.entries jar))
              names        (map (fn [x] (.getName x)) entries)
              snames       (filter (fn [x] (= 0 (.indexOf x inner-dir))) names)
              fsnames      (map #(subs % (count inner-dir)) snames)]
          fsnames)))
    
    (defn read-from-jar [jar-path inner-path]
      (if-let [jar   (JarFile. jar-path)]
        (if-let [entry (.getJarEntry jar inner-path)]
          (slurp (.getInputStream jar entry)))))
    
    

    Usage:

    
    (read-from-jar "/Users/Chris/.m2/repository/lein-newnew/lein-newnew/0.3.5/lein-newnew-0.3.5.jar"
                   "leiningen/new.clj")
    
    ;=> "The list of built-in templates can be shown with `lein help new`....."
    
    (list-jar  "/Users/Chris/.m2/repository/lein-newnew/lein-newnew/0.3.5/lein-newnew-0.3.5.jar" "leiningen")
    ;; => (new/app/core.clj new/app/project.clj .....)
    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are there any Clojure http libraries that use the java.net.URLConnection class? Reason I'm asking
Is there a way to easily generate java beans given a vector in clojure?
Are there any java or clojure mail libraries out there that do what lamson
I'd like to call a Clojure function from Java code. This question hasn't been
The Joy of Clojure says not to rationalize values that are Java float or
I'm learning how to extend Java classes in Clojure, but I don't see a
I am trying to build my project that has some java source and clojure
I'm using the Eclipse Export... Runnable jar file feature to package up my Clojure+Java
In projects where there is a mix of java and clojure code such as,
Is there a way to make Java Exceptions more informative? For example, take this

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.