I'm totally new to clojure and leiningen, all I want to do is write some java code that will use this library https://github.com/nathanmarz/dfs-datastores
Here is what I did :
Created a new leiningen project.
Added [com.backtype/dfs-datastores "1.3.6"] to my :dependencies ( I checked my .m2/repository/com/backtype/dfs-datastores/1.3.6 and there are some jar files there)
Created a new .java file in the main project directory with some code.
Now how can I use the dfs-datastores code inside my .java file ?
Related
How to create an executable jar project for Geb-Groovy based project in eclipse.
The following is the directory structure:
the pages package contains the groovy files
the testclasses package contains the test cases groovy files
the utils package contains the groovy files to read data of excel sheets.
Detailed instructions for creating the jar file would be highly appreciated.
If the project you are working with is a gradle project I would recommend looking at a task called "shadowJar" https://github.com/johnrengelman/shadow
in build.gradle would have something like this:
apply plugin: "com.github.johnrengelman.shadow"
mainClassName = '<Name of your Main Class>' //This will act as the jar's main point of entry the 'Main' method found in this class will be executed when the jar is executed
shadowJar {
manifest {
attributes 'Main-Class': mainClassName
}
}
Then you simply make a run the shadowJar task and a jar file is generated in your build folder. It should also contain all your dependencies as well.
Could clojure.java.io/resource load file from classpath but outside of the jar file? When I put file within jar file, it'd load file but when I put file outside jar but in classpath it'd not load file.
Example
Jar name: hello.jar
within jar there is file hello.txt
java -jar hello.jar
I saw no problem to read file hello.txt file using line bellow
(->
"hello.txt"
(clojure.java.io/resource)
(clojure.java.io/file)
(slurp))
But when I put hello.txt outside of the jar but in classpath, it fails to load file.
java -cp . -jar hello.jar
hello.txt file in same directory with hello.jar file.
Br,
Mamun
You can't mix -cp and -jar cmdline arguments in that way. You can either do...
java -cp ".:hello.jar" com.foo.Class # should use ; instead of : on Windows
or add a
Class-Path: /some/dir/with/hello /some/dir/with/hello/hello.jar
entry to the jar META-INF/MANIFEST.MF file that includes local directory.(details)
I would recommend you don't use . as the directory, since this will be prone to errors or maybe security issues if the jar file moves.
in the sample project,
https://github.com/technomancy/leiningen/blob/master/sample.project.clj
on line 217, there is a directive for including non-code files :
:resource-paths ["src/main/resource"] ; non-code files included in classpath/jar
I have a resources folder in my project and this line in my project.clj
:resource-paths ["resources"] ; non-code files included in classpath/jar
however, when I run lein jar to generate the .jar file, it does not package up the resources folder.
Is there something that I am missing?
Actually, it did get packaged. I just was not looking in the right spot:
from:
Resources in Clojure applications
'Leiningen borrows the convention for resources from maven, with slightly different folder layouts. The rule states that the resources folder must be used as a compile time classpath root, meaning that leiningen is right in putting all the files inside resources folder in the root location inside the jar.'
I thought that a resources directory would get created with the jar itself but lein jar copied all the files in the resources directory to the root of the jar.
here is a very specific question re the clojure class path and lein / emacs
lets say I'm working with a project and have a repl with clojure-jack-in. I need to add a new dependency to this project, is there any way to run lein deps and then be able to use the downloaded .jar in the open repl right away (possibly a repl command?)?
right now whenever I need to add a new dependency I need to reset the swank/slime connection for it to become visible in the classpath.
Thanks
I see three options:
Use Jark to start a REPL on a JVM that can handle new jar files at runtime (http://icylisper.in/jark/index.html)
add-classpath method in clojure (breaks sometimes ... http://groups.google.com/group/clojure/browse_thread/thread/43a413ae55ed25d0)
Write your own code to add the new jar file (http://groups.google.com/group/clojure/browse_thread/thread/0095ea6e918c430e)
I have a project that is going to create hotspot client, so it imports net.rim.device.api.wlan.hotspot.*
When the code runs it complains that it cannot find net_rim_api_wlan_hotspot. If I display the table-of-contents for the jar file, *\BlackBerry JDE 5.0.0\lib\net_rim_api.jar, the file class files are listed.
What steps am I missing to build the project correctly?