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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:54:57+00:00 2026-05-13T10:54:57+00:00

How do you load program resources such as icons, strings, graphical elements, scripts, and

  • 0

How do you load program resources such as icons, strings, graphical elements, scripts, and so on in a Clojure program? I am using a project layout similar to that in many Java projects where there is a “resources” directory hanging off of a “source” directory. A jar file is created from the source and includes the resources, but I can’t seem to get the resources loaded as I would in Java.

The first thing I tried was something like

(ClassLoader/getSystemResource "resources/myscript.js")

But could never find the resource.

You can do something similar with

...
  (let [cls (.getClass net.mydomain.somenamespace)
        strm (.getResourceAsStream cls name)        ]
...

where name is the name of the resource to load, but the stream is nil.

You can try using the context class loader with something like

...

(let [thr (Thread/currentThread)
      ldr (.getContextClassLoader thr)
      strem (.getResourceAsStream ldr name)]
...

But strem is always nil.

In frustration, I’ve tried placing the resource files in just about every directory in the program. They get copied into the jar correctly, but I still can’t seem to load them.

I’ve looked at the language sources for the load function and the run-time library, but am not “getting” it.

Any help would be appreciated.

EDIT: Here’s a more concrete example. In Java, if you wanted to convert MarkDown to HTML, you might use the showdown.js script and write something like:

package scriptingtest;

import java.io.InputStreamReader;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

public class Example {

    private Object converter;

    public String transformMarkDown(String markdownString) {
        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByName("js");
        try {
            engine.eval(new InputStreamReader(getClass().getResourceAsStream(
                    "resources/showdown.js")));
            converter = engine.eval("new Showdown.converter()");
        } catch (Exception e) {
            return "Failed to create converter";
        }
        try {
            return ((Invocable) engine).invokeMethod(converter, "makeHtml",
                    markdownString).toString();
        } catch (Exception e) {
            return "Conversion failed";
        }
    }

    public static void main(String[] args) {
        System.out.println(new Example().transformMarkDown("plain, *emphasis*, **strong**"));
    }
}

when I create the project, it all gets compiled and packed into a jar. When run, the program outputs <p>plain, <em>emphasis</em>, <strong>strong</strong></p>

A literal translation to Clojure seems pretty straightforward, but I run into trouble trying to create the InputStreamReader — I can’t seem to write the code needed to find the script file in the jar.

Edit: Added “markdown” tag since the post gives two complete examples of approaches to processing markdown.

  • 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-13T10:54:57+00:00Added an answer on May 13, 2026 at 10:54 am

    It’s the directory structure.

    Continuing with the scripting engine example in the OP, a Clojure equivalent would be:

    (ns com.domain.example
      (:gen-class)
      (:import (java.io InputStreamReader))
      (:import (javax.script ScriptEngineManager ScriptEngine)))
    
    (defn load-resource
      [name]
      (let [rsc-name (str "com/domain/resources/" name)
            thr (Thread/currentThread)
            ldr (.getContextClassLoader thr)]
        (.getResourceAsStream ldr rsc-name)))
    
    (defn markdown-to-html
      [mkdn]
      (let [manager (new ScriptEngineManager)
            engine (.getEngineByName manager "js")
            is (InputStreamReader. (load-resource "showdown.js"))
            _ (.eval engine is)
            cnv-arg (str "new Showdown.converter().makeHtml(\"" mkdn "\")")]
        (.eval engine cnv-arg)))
    
    (defn -main
      []
      (println (markdown-to-html "plain, *emphasis*, **strong**")))
    

    Note that the path to the resources is com/domain/resources for this code as opposed to com/domain/scriptingtest/resources in the Java version. In the clojure version, the source file, example.clj is in com/domain. In the Java version, the source file, Example.java is in the com/domain/scriptingtest package.

    When setting up a project in my IDE, NetBeans, the Java project wizard asks for an enclosing package for the source. The Clojure plugin, enclojure, asks for a namespace, not a package. I had never noted that difference before. Hence the “off-by-one” error in the directory structure expected.

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

Sidebar

Related Questions

How can i use NSSearchField for filter data that i load into program with
I have a program, that takes a long time to load. Because of this,
I'd like to ask how could I load textures from program resources. This code
I am trying to create a Multi-Language WPF program that will load it's languages
I'm using a simple program that will take tallPDF xml and convert it into
I am currently doing some I/O intensive load-testing using python. All my program does
I have an AVI file that I pulled from shell32 using Resources Extract .
I have a simple web.py program to load data. In the server I don't
i am new kernel programming.i have been trying to load this driver program for
I'm writing a program which will allow to load a specific managed .DLL file

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.