24

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.

2 Answers 2

18

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!

Sign up to request clarification or add additional context in comments.

3 Comments

Error: Could not find or load main class [prueba.core]. I have included :main and its corresponding value, and I have a -main function that is public in that namespace. Any idea on what might be going wrong?
Hi @m0skit0, it's been a while since I wrote this. Have you structured structured your directories appropriately? By that I mean is your project.clj in a folder containing src containing prueba containing core.clj? Did you use lein new <PROJECT NAME> and then edit the core.clj file created? If not, could you explain what you have done as clearly as possible?
Project structure is correct because it's created by Leiningen. I finally got it to work, by using the following syntax :main root.scriptlauncher :aot [root.scriptlauncher] for the defproject.
3

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. 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 has a menu for adding libraries. You will need to add clojure[-contrib].jar to both the build and run libraries

1 Comment

I've tried adding that as both a compile time and run time library to the project, but no luck so far.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.