简体   繁体   English

从clojure项目创建可执行jar文件?

[英]Creating an executable jar file from a clojure project?

I have a clojure project that uses the slick 2d game engine that I am trying to run as an executable jar file. 我有一个clojure项目,使用光滑的2D游戏引擎,我试图作为可执行jar文件运行。 I created the project in both Netbeans and Eclipse and I have had no luck exporting them into an executable format. 我在Netbeans和Eclipse中创建了这个项目,我没有把它们导出成可执行格式的运气。 It keeps giving the error could not find the main class, followed by giving my main class. 它一直给错误找不到主类,然后给我的主类。 I have tried editing the manifest file changing the name in the hopes that it will find it but no luck so far. 我已经尝试编辑清单文件来更改名称,希望它能找到它但到目前为止没有运气。

It does run in the development environment, but not outside it. 它确实在开发环境中运行,但不在其外部运行。

It's been a while since I posted this question and I thought that I would stick up what I've found since for anyone who needs this question answered. 自从我发布这个问题已经有一段时间了,我认为我会坚持我发现的,因为对于需要回答这个问题的人来说。

I now use Leiningen to manage my projects though I have started playing around with cljr which is a repl and package manager that complements it. 我现在使用Leiningen来管理我的项目,虽然我已经开始使用cljr ,这是一个补充它的repl和包管理器。 Either of these make it much simpler to generate a runnable jar file. 这些都可以使生成可运行的jar文件变得更加简单。

Taking Leiningen as an example set it up using the instructions on the site and then call lein new in your workspace. 以Leiningen为例,使用网站上的说明进行设置,然后在工作区中调用lein new This will create a folder to house your projects as well as a sub-folders for your source and tests a readme file and a project.clj file. 这将创建一个文件夹来存放项目以及源文件的子文件夹,并测试自述文件和project.clj文件。

Edit the project.clj with the dependencies that you will be using. 使用您将使用的依赖项编辑project.clj。 Dev-dependencies are dependencies which you need purely for development such as swank-clojure shown in the example below. 开发依赖项是纯粹用于开发的依赖项,例如下面示例中显示的swank-clojure。

(defproject myproject "0.0.1-SNAPSHOT"
  :description "My Personal Project."
  :url "http://example.com/my-project"
  :dependencies [[org.clojure/clojure "1.1.0"]
                 [org.clojure/clojure-contrib "1.1.0"]
                 [**other dependencies**]]
  :dev-dependencies [[swank-clojure "1.2.1"]]
  :main [org.myproject.core])

I find swank-clojure useful as you can then type lein swank to start a swank instance which you can connect to via emacs. 我发现swank-clojure很有用,因为你可以输入lein swank来启动一个lein swank实例,你可以通过emacs连接到它。

:main defines what namespace contains the -main function. :main定义哪个命名空间包含-main函数。

Calling lein uberjar will create a standalone jar which will then run. 调用lein uberjar将创建一个独立的jar,然后运行。

Hopefully that helps anyone who had my problem! 希望这可以帮助任何有问题的人!

I had to add clojure.jar and clojure-contrib.jar as a "dependency" to the project to cause it to be included in the jar. 我不得不将clojure.jar和clojure-contrib.jar添加为项目的“依赖项”,以使其包含在jar中。 once I got that I was able to run the resulting jar. 一旦我得到了,我就可以运行生成的罐子。 Keep in mind that Netbeans has its own clojure.jar that is used for running the plugin its self and this does not need to be the same clojure.jar that your program uses. 请记住,Netbeans有自己的clojure.jar,用于自行运行插件,这不需要与程序使用的clojure.jar相同。 Netbeans has a menu for adding libraries. Netbeans有一个添加库的菜单。 You will need to add clojure[-contrib].jar to both the build and run libraries 您需要将clojure [-contrib] .jar添加到构建和运行库中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM