How to distribute Clojure GUI apps? How Clojure compares to Vala in this subject?
Asked Answered
C

3

6

Double question here.

So I built a simple GUI app with Clojure (using seesaw) in just a few minutes and that was really fun! But now I don't know how to actually release it. I would like it to run as a stand alone app. How should I "compile" and distribute Clojure GUI apps?

I'm also interested in Vala and would like to know how different is the release process for both languages. From the release / distribution point of view, what are the advantages and disadvantages for each side?

Ca answered 10/8, 2014 at 2:44 Comment(1)
Answers are good, but I'm still waiting for a more detailed response that kinda wraps everything :)Ca
A
3

Set up your project to run as a standalone Java application by specifying the core name space (i.e app.core) to be the main class invoked for the jar file by specifying it with :main. In addition, add a uberjar profile for AOT compilation.

project.clj:

(defproject app "1.0.0-SNAPSHOT"
  :description "app Example."
  :dependencies
    [[org.clojure/clojure "1.8.0"]]
  :profiles {:uberjar {:aot :all}}
  :main app.core)

Ensure you have :gen-class specified in the name-space of your program. Also define a -main function to act as the main entry point.

src/app/core.clj:

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

(defn -main [& args]
  (dostuff ""))

Then use Packr (https://github.com/libgdx/packr), a small application for packaging up a JAR, assets and a JVM for distribution on Windows, Linux and Mac OS X.

Create a Packr configuration file.

config.json

{
  "platform": "mac",
  "jdk": "/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/",
  "executable": "My App",
  "classpath": [
    "target/app-1.0.0-SNAPSHOT-standalone.jar"
  ],
  "mainclass": "app.core",
  "icon": "resources/icon.icns",
  "minimizejre": "soft",
  "output": "myapp.app"
}

then run

$ lein uberjar
$ java -jar packr.jar config.json

You will now have a package that can be distributed as native app. This process works well for GUI apps. Sorry i know nothing about Vala.

Albumin answered 24/10, 2016 at 3:50 Comment(1)
I'm accepting this because it's the most detailed answer until now.Ca
F
6

The best way to release a Clojure project as an application is to use lein uberjar to create a standalone jar containing all of your dependencies. Any user with a compatible jvm can run java -jar your-uberjar.jar in order to run your application.

There are some complications that come up if your application was written in a way that it expects the contents of the project directory to exist at runtime. clojure.java.io/resource allows resources to be used whether they are present in the current directory tree, or packaged into an uberjar containing your app.

Felipa answered 10/8, 2014 at 3:42 Comment(2)
I really like your answer and would love to accept it, but it has no comparison with Vala GUI app deployment.Ca
my apologies, I am not qualified to comment on the state of the art in vala deployment, library version issues with vala, cross platform compatibility issues in vala, etc. I do know from experience that an uberjar made by lein will run on any jvm of sufficient version (1.6+ usually suffices, depending on classes used by your code).Felipa
A
3

Set up your project to run as a standalone Java application by specifying the core name space (i.e app.core) to be the main class invoked for the jar file by specifying it with :main. In addition, add a uberjar profile for AOT compilation.

project.clj:

(defproject app "1.0.0-SNAPSHOT"
  :description "app Example."
  :dependencies
    [[org.clojure/clojure "1.8.0"]]
  :profiles {:uberjar {:aot :all}}
  :main app.core)

Ensure you have :gen-class specified in the name-space of your program. Also define a -main function to act as the main entry point.

src/app/core.clj:

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

(defn -main [& args]
  (dostuff ""))

Then use Packr (https://github.com/libgdx/packr), a small application for packaging up a JAR, assets and a JVM for distribution on Windows, Linux and Mac OS X.

Create a Packr configuration file.

config.json

{
  "platform": "mac",
  "jdk": "/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/",
  "executable": "My App",
  "classpath": [
    "target/app-1.0.0-SNAPSHOT-standalone.jar"
  ],
  "mainclass": "app.core",
  "icon": "resources/icon.icns",
  "minimizejre": "soft",
  "output": "myapp.app"
}

then run

$ lein uberjar
$ java -jar packr.jar config.json

You will now have a package that can be distributed as native app. This process works well for GUI apps. Sorry i know nothing about Vala.

Albumin answered 24/10, 2016 at 3:50 Comment(1)
I'm accepting this because it's the most detailed answer until now.Ca
T
2

Vala projects are typically distributed by the project as source tarballs. Most Vala projects use autotools as their build system; once you have autotools set up, you just type make dist to and one will be built for you.

If there is demand for your software, that tarball is then packaged for various distributions by their packagers, so that people can install it through whatever package manager that distribution uses (i.e., apt-get install yourpkg on Debian/Ubuntu, yum install yourpkg on Fedora, Red Hat, OpenSUSE, etc.) or a GUI such as GNOME Software.

Tomaso answered 10/8, 2014 at 16:49 Comment(2)
Great asnwer, so with Vala I basically have to rely on autotools and maintain the build scripts while with closure I simply exec lein uberjar :)Ca
You don't have to, but it's what most people prefer (both developers and users). You could use a different build system (CMake, waf, etc.), or you could just compile your program directly with valac and distribute the executable (though it won't be very portable). Most Vala software is targeted at Linux, and Linux users expect distribution-specific packages which are linked dynamically to system libraries, not a massive blob of binary data. This isn't really a Vala thing, it's a Linux thing--see fedoraproject.org/wiki/Packaging:No_Bundled_LibrariesTomaso

© 2022 - 2024 — McMap. All rights reserved.