Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating an executable jar file from a clojure project?

Tags:

I have a clojure project that uses the slick 2d game engine that I am trying to run as an executable jar file. I created the project in both Netbeans and Eclipse and I have had no luck exporting them into an executable format. 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.

like image 973
toofarsideways Avatar asked Oct 14 '09 13:10

toofarsideways


People also ask

How do I create an executable jar file?

Right click on your Java Project and select Export. Select Java -> Runnable JAR file -> Next. Select the Destination folder where you would like to save it and click Finish.

How do I make a jar file executable in Linux?

However, to make the jar file itself executable, you need to set the executable bit, as the message hints. chmod +x /path/to/your/file/myFile. jar will accomplish this. After that you can do ./myFile.

Is a jar file an executable?

A Java Archive, or JAR file, contains all of the various components that make up a self-contained, executable Java application, deployable Java applet or, most commonly, a Java library to which any Java Runtime Environment can link.


1 Answers

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. Either of these make it much simpler to generate a runnable jar file.

Taking Leiningen as an example set it up using the instructions on the site and then call lein new in your workspace. 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.

Edit the project.clj with the dependencies that you will be using. Dev-dependencies are dependencies which you need purely for development such as swank-clojure shown in the example below.

(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.

:main defines what namespace contains the -main function.

Calling lein uberjar will create a standalone jar which will then run.

Hopefully that helps anyone who had my problem!

like image 142
toofarsideways Avatar answered Sep 23 '22 13:09

toofarsideways