如何从Java应用程序内部运行clojure uberjar?

时间:2020-07-28 09:29:17

标签: java java-8 clojure uberjar

我可以像这样从命令行平稳运行this clojure uberjar

java -jar metabase.jar

我试图通过Java应用程序执行相同的操作。使用ProcessBuilder可以正常工作。但是,失败并显示URLClassLoader

这是我的代码和抛出的异常:

private void startMetabase() {
    try {
        URL metabaseJarURL = new File("/path/to/metabase.jar").toURI().toURL();
        URLClassLoader child = new URLClassLoader(new URL[] { metabaseJarURL }, this.getClass().getClassLoader());

        Class<?> classToLoad = Class.forName("metabase.core", true, child);

        Method main = classToLoad.getDeclaredMethod("main", String[].class);

        Object[] args = new String[] {};
        main.invoke(null, args);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

例外

java.lang.ExceptionInInitializerError: null
    at clojure.lang.Namespace.<init>(Namespace.java:34)
    at clojure.lang.Namespace.findOrCreate(Namespace.java:176)
    at clojure.lang.Var.internPrivate(Var.java:156)
    at metabase.core.<clinit>(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at my.Poc.startMetabase(KeywordsFinder.java:69)
    at my.Poc.main(KeywordsFinder.java:32)
Caused by: java.io.FileNotFoundException: Could not locate clojure/core__init.class, clojure/core.clj or clojure/core.cljc on classpath.
    at clojure.lang.RT.load(RT.java:462)
    at clojure.lang.RT.load(RT.java:424)
    at clojure.lang.RT.<clinit>(RT.java:338)
    ... 8 common frames omitted

我想念什么?

0 个答案:

没有答案