如何在运行从'lein uberjar'的jar时设置类路径? [英] How to setup the classpath when running the jar made from 'lein uberjar'?

查看:128
本文介绍了如何在运行从'lein uberjar'的jar时设置类路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个hello.clj如下。

 (ns hello)
(defn hi [](printlnHI))

通常,我可以使用main.clj中的这个函数,如下所示。 hello.clj在包含main.clj的同一目录中。和类路径包括。 (当前路径)。

 (使用'hello)
(hi)


我用'lein new myproject; lein deps'得到以下结构。

 

| - README
| - classes
| ` - myproject
| - lib
| | - clojure-1.2.0-beta1.jar
| | - clojure-contrib-1.2.0-beta1.jar
| ` - lucene-core-3.0.2.jar
| - project.clj
| - src
| ` - myproject
| ` - core.clj
` - test
` - myproject
` - test
` - core.clj

project.clj如下。

 (defproject myproject1.0.0 -SNAPSHOT
:descriptionFIXME:write
:dependencies [[org.clojure / clojure1.2.0-beta1]
[org.clojure / clojure-contrib 0-beta1]
[org.apache.lucene / lucene-core3.0.2]]
:main myproject.core)

而且core.clj如下。

 (ns myproject .core 
(:gen-class))

(use'hello)

(defn test1 [](printlnhello))

(defn -main [& args]
(do
(println欢迎来到我的项目!这些是你的参数:args)
(test1)
(hi)))

现在,我在哪里放hello.clj?
我试图将其复制到myproject / src目录并运行uberjar来获取jar。但是,运行该jar会导致此错误消息。

 
prosseek:myproject smcho $ java -jar myproject-1.0.0-SNAPSHOT- standalone。 jar add
线程main中的异常java.lang.ExceptionInInitializerError
原因:java.io.FileNotFoundException:无法在类路径上找到hello__init.class或hello.clj:(core.clj:0)
...




  • 可能有什么问题?错误消息说hello.clj不在类路径上。但是,如何使用lein uberjar设置类路径?



我上传了项目此处

解决方案

你把hello.clj放在src / myproject下,所以它的ns应该是myproject.hello。有了这个文件结构,我希望hello.clj说(ns myproject.hello)和core.clj说(使用'myproject。



当我进行这些更改时,我会得到:

  $ java -jar myproject-standalone.jar abc 
欢迎来到我的项目!这些是你的参数:(a b c)
hello
HI


I have a hello.clj as follows.

(ns hello) 
(defn hi [] (println "HI"))

Normally, I can use this function from main.clj as follows. The hello.clj is in the same directory that contains main.clj. And the classpath includes . (current path).

(use 'hello)
(hi)

How can I use this hello.clj for the 'lein uberjar'?

I used 'lein new myproject; lein deps' to get the following structure.

.
|-- README
|-- classes
|   `-- myproject
|-- lib
|   |-- clojure-1.2.0-beta1.jar
|   |-- clojure-contrib-1.2.0-beta1.jar
|   `-- lucene-core-3.0.2.jar
|-- project.clj
|-- src
|   `-- myproject
|       `-- core.clj
`-- test
    `-- myproject
        `-- test
            `-- core.clj

project.clj is as follows.

(defproject myproject "1.0.0-SNAPSHOT"
  :description "FIXME: write"
  :dependencies [[org.clojure/clojure "1.2.0-beta1"]
                 [org.clojure/clojure-contrib "1.2.0-beta1"]
                 [org.apache.lucene/lucene-core "3.0.2"]]
  :main myproject.core)    

And core.clj is as follows.

(ns myproject.core
  (:gen-class))

(use 'hello) 

(defn test1 [] (println "hello"))

(defn -main [& args]
  (do 
    (println "Welcome to my project! These are your args:" args)
    (test1)
    (hi)))

Now, where do I put the hello.clj? I tried to copy it to myproject/src directory and run uberjar to get the jar. But, running the jar causes this error message.

prosseek:myproject smcho$ java -jar myproject-1.0.0-SNAPSHOT-standalone.jar a d d
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.io.FileNotFoundException: Could not locate hello__init.class or hello.clj on classpath:  (core.clj:0)
...

  • What might be wrong? Error messages says hello.clj is not on the class path. But, how to setup the classpath with 'lein uberjar'?

I uploaded the project here.

解决方案

You put hello.clj under src/myproject so it's ns should be myproject.hello. With this file structure, I would expect hello.clj to say (ns myproject.hello) and for core.clj to say (use 'myproject.hello).

When I make those changes, I get:

$ java -jar myproject-standalone.jar a b c
Welcome to my project! These are your args: (a b c)
hello
HI

这篇关于如何在运行从'lein uberjar'的jar时设置类路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆