I have created a new project with
lein new app lern
which gives me this project.clj:
(defproject lern "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.7.0"]
[seesaw "1.4.5"]]
:main ^:skip-aot lern.core
:target-path "target/%s"
:profiles {:uberjar {:aot :all}})
I do have (:gen-class) in my ns decleration and a (-main) in my core.clj file. Now being in the project directory (lern) doing: lein uberjar doesn't create any jar file inside of my target directory. What am i doing wrong?
Related
I want to use a changeable file in clojure-project. (Manjaro Linux & Leiningen 2.8.0 on Java 1.8.0_144 OpenJDK 64-Bit Server VM)
So, I tried ... ($ echo resources/temp.txt => Hello )
(ns test.core
(:require [clojure.java.io :refer [writer input-stream]]
[clojure.java.io :as io])
(:gen-class))
(str (io/resource ""))
(defn -main
[]
(with-open [r (input-stream (io/resource "temp.txt"))]
(loop [c (.read r)]
(if (not= c -1)
(do
(print (char c))
(recur (.read r))))))
(with-open [r (writer (.getFile (io/resource "temp.txt")))]
(.write r "See you!"))
)
and project.clj is here ...
(defproject test "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.8.0"]]
:main test.core)
This program can run in lein-run
$ lein run
Hello
$
But this cannot run in lein-uberjar -> java -jar test-0.1.0-SNAPSHOT-standalone.jar
$ lein uberjar
$ java -jar test-0.1.0-SNAPSHOT-standalone.jar
Exception in thread "main" java.io.FileNotFoundException: /home/***/Documents/test/target/test-0.1.0-SNAPSHOT-standalone.jar!/temp.txt (
No such file or directory)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(FileOutputStream.java:270)
at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
at clojure.java.io$fn__9522.invokeStatic(io.clj:230)
at clojure.java.io$fn__9522.invoke(io.clj:230)
at clojure.java.io$fn__9459$G__9428__9466.invoke(io.clj:69)
at clojure.java.io$fn__9526.invokeStatic(io.clj:242)
at clojure.java.io$fn__9526.invoke(io.clj:240)
at clojure.java.io$fn__9459$G__9428__9466.invoke(io.clj:69)
at clojure.java.io$fn__9534.invokeStatic(io.clj:261)
at clojure.java.io$fn__9534.invoke(io.clj:259)
at clojure.java.io$fn__9459$G__9428__9466.invoke(io.clj:69)
at clojure.java.io$fn__9496.invokeStatic(io.clj:166)
at clojure.java.io$fn__9496.invoke(io.clj:166)
at clojure.java.io$fn__9472$G__9424__9479.invoke(io.clj:69)
at clojure.java.io$writer.invokeStatic(io.clj:119)
at clojure.java.io$writer.doInvoke(io.clj:104)
at clojure.lang.RestFn.invoke(RestFn.java:410)
at test.core$_main.invokeStatic(core.clj:15)
at test.core$_main.invoke(core.clj:7)
at clojure.lang.AFn.applyToHelper(AFn.java:152)
at clojure.lang.AFn.applyTo(AFn.java:144)
at test.core.main(Unknown Source)
How do I get correct path to it?
Thank you.
One problem is that .getFile doesn't work in a jar file, because you're reading from a zip file, not a directory structure on the file system.
Also, it's not recommended to change files inside a jar file (I'm not sure it's even possible). Also see Reading a resource file from within jar.
I have a project with layout
MyProject
-- src
-- target
-- myfiles
-- myfile1.txt
-- myfile2.txt
-- built.sbt
Now I want to package myfiles/myfile1.txt and myfiles/myfile2.txt into the output jar.
I tried to include this to the build.sbt file:
mappings in (Compile, packageBin) += {
baseDirectory.value / "myfiles" / "myfile1.txt" -> "File/myfile1.txt"
}
mappings in (Compile, packageBin) += {
baseDirectory.value / "myfiles" / "myfile2.txt" -> "File/myfile2.txt"
}
but when I am using sbt assembly command, they are not included in the jar.
Where is wrong?
I'm trying to understand how to properly setup JavaFX to work with a Clojure project. By reading various sources this is what I've come up with:
This is project.clj:
(defproject cljfx "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.8.0"]]
:resource-paths ["lib/jfxrt.jar"]
:main ^:skip-aot cljfx.core
:target-path "target/%s"
:profiles {:uberjar {:aot :all}})
I don't know if I should use :resource-paths or add JavaFX to the classpath via the :dependencies vector...
This is core.clj:
I've basically translated to Clojure an example from this tutorial:
http://docs.oracle.com/javafx/2/get_started/hello_world.htm
(ns cljfx.core
(:gen-class
:extends javafx.application.Application)
(:import
[javafx.application Application]
[javafx.stage Stage]
[javafx.scene Scene]
[javafx.scene.control Button]
[javafx.scene.layout StackPane]
[javafx.event ActionEvent EventHandler]))
(defn -main [& args]
(Application/launch cljfx.core args))
(defn button [text]
(doto (Button.)
(.setText (str "Say " text))
(.setOnAction (proxy [EventHandler] []
(handle [event]
(println text))))))
(defn -start [primaryStage]
(let [root (doto (StackPane.)
(-> (.getChildren)
(.add (button "Hello World!"))))]
(doto primaryStage
(.setScene (Scene. root 300 250))
(.show))))
This doesn't compile, and I don't know what I'm doing wrong... can you help me?
Here is the error:
http://pastebin.com/sYeK7MJd
There may be other problems, but the root problem in the pastebin log is:
Caused by: clojure.lang.ArityException: Wrong number of args (2) passed to: core/-start
When using gen-class and providing method implementations, every method needs to take the instance itself as the first parameter. The convention is to use "this":
(defn -start [this primaryStage]
Try that, and ensure that local instance method calls are applied to "this".
How can I modify the output of the final packaged zip to move the "lib" directory contents up one level. Basically I output a zip and the contents are like so:
ZIP FILE CONTENT:
-- my-plugin-1.0.jar
-- /lib
-- /lib/mydependency1.jar
-- /lib/mydependency2.jar
ZIP FILE CONTENT I WISH TO HAVE:
-- my-plugin-1.0.jar
-- mydependency1.jar
-- mydependency2.jar
I want to move everything in "lib" up one level to the root output.
sbt version 0.13.0
Here is my build.sbt:
import NativePackagerHelper._
organization := "com.company.product"
name := "my-plugin"
version := "1.0"
enablePlugins(UniversalPlugin)
packageName in Universal:= "deployment"
publishArtifact in (Compile, packageDoc) := false
artifactName := {
(sv: ScalaVersion, module: ModuleID, artifact: Artifact) =>
artifact.name + "-" + module.revision + "." + artifact.extension
}
javacOptions ++= Seq("-source", "1.8")
mappings in Universal <+= packageBin in Compile map { jar => jar -> (jar.getName()) }
topLevelDirectory := None
plugins.sbt
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.0.0")
command line:
sbt universal:packageBin
Looks like your requirement is a first class citizen in sbt-native-packager:
mappings in Universal ++= contentOf("src/main/resources/cache")
I have to copy resources under app/ folder to classpath. This is what I did. But all files under app/assets/css will end up at assets/css in the jar. How can I tell sbt to move all app/assets to public folder in the jar.
val assetsS = Seq(
unmanagedResourceDirectories in Compile <+= scalaSource in Compile,
excludeFilter in unmanagedResources in Compile := "*.scala" || "*.java" || "*.js" || "*.less" || "*.coffee"
)