I have downloaded and installed a jar with Maven (as answered here) but now I need to require it inside of a project. I followed the instructions on the git README ((require '[clj-http.client :as client])) but I still get this error:
FileNotFoundException Could not locate clj_http/client__init.class or clj_http/client.clj on classpath: clojure.lang.RT.load (RT.java:430)
The other answers on this thread will certainly work .... But adding jars directly on your machine's CLASSPATH or at the command line can be a very difficult strategy for development . . .
The most common, idiomatic way to include jars in a clojure app is Leiningen (easy, one step install on github -- begginers should check note at the end of this answer for a caveat)... Leiningen can also install the clojure environment and launch your repl for you, preloaded with the right jar environment.
It is essentially a java dependency manager and build tool rolled into one - i.e. like ivy or the maven Pom.xml which we use for java development.
A Few examples of how to use Leiningen to interact with multiple libs in a simple and scalable fashion :
To launch a repl, such that the jars in your project.clj file are on the classpath :
lein repl
To update your jars in your maven repo specified by your project.clj :
lein deps
Finally , lein let's you export "uberjars" which are akin to "fatjars", i.e. they have all the dependencies bundled for you.
A minor update regarding the new Lein version : Note for begginers.
There are two scripts you can run to install Leiningan, it might be safer to run this one:
https://github.com/jayunit100/leiningen/blob/stable/bin/lein (the stable release)
Rather than this one:
https://raw.github.com/technomancy/leiningen/preview/bin/lein (the latest update, which is a preview).
when you start the java process you need to do:
java -cp ./lib/clj-http.jar ./lib/clojure.jar clojure.main
Basically you need both clojure.jar (which is where the REPL is at) AND clj-http.jar in the classpath.
Assuming clj-http.jar is in ./lib/ directory. Or you could build your project with lein (build tool, similar to maven) and have it build an uberjar, which is what I would do. There's a pretty good walkthrough of setting up lein and building an uberjar here: http://zef.me/2470/building-clojure-projects-with-leiningen.
add clj-http.jar to CLASSPATH or CP before you start clojure repl.
Related
I need to execute a maven plugin on a system that does not have both maven and java installed and installing both of them on the system is not an option. While searching for the ways, I found out that by using gradle we can build executable binaries that does not even require gradle to get executed, which perfectly fits my situation :) . Is there any way to execute maven plugins by using gradle. Thanks in advance
Java is required for Maven and for Gradle too.
You can use Maven Wrapper exactly like with Gradle.
Execute this command in project directory (this creates executable script like in gradle)
mvn -N io.takari:maven:wrapper
To invoke this project without maven installed use:
./mvnw GOAL
Gradle is a build system. You can build anything with it, including native binaries.
And yes, you can call Maven Plugins from Gradle, as Maven Plugins are written in Java and Gradle is based on Groovy and thus on Java.
But both facts have nothing to do with each other.
You can of course also use Gradle (or any other build system including manually stuffing things together) to build a distributable that includes a Java runtime environment. But then Java is, as said, shipped with your result. You cannot run Java code without having Java around, besides porting the Java code to something else like C++ that compiles to a native binary.
Yes, you can also call Java code from native code if you do some glueing, but no, also this will not work without having Java around, because that's the way Java works.
Both Maven and Gradle require java to be installed. See https://docs.gradle.org/current/userguide/installation.html
There is a working jar file on Github version 1.4 (https://github.com/ggodlewski/smux-anki-converter/downloads)
The original author has updated the code to versions: 1.5, 1.6 and 1.7 but they are not standalone working jar files but mere zip files containing:
.classpath,
.gitignore,
.project
pom.xml
and some of the folders contained in the working version 1.4.
Version 1.4 is about 7MB and the updates are only about 45kB each.
The project itself seems to be dead and I cannot get in touch with the author.
My question is: how do I make those updates work? How to update version 1.4 to 1.7 on my PC?
I have tried to figure it out using Eclipse import/export but I am not a programmer and I just don't know how to do it.
Please help.
You should be able to build from source as follows:
Make sure that you have a Java JDK installed. Java 6 or later is required, but I would advise Java 7 or Java 8.
Make sure you have Maven installed and configured. (If you need to use an HTTP proxy to access the internet, you will need to instruct Maven ...)
Use git clone <url> to create a clean sandbox.
Change directory to the sandbox.
Run mvn assembly:assembly to build. (That is what the README file says ...)
The first time you do this, Maven is probably going to download a lot of stuff from the Maven Central repo.
If it works, the built JAR(s) will be somewhere in the target subdirectory.
(Note: I haven't tried this myself. YMMV.)
I want to be set an archetype for a stable JavaFX (Java 8) Maven build that will produce an executable JAR that (always) runs from the command line. And preferable without needing to build an UberJar or similar.
When we use the Netbeans 'Maven JavaFX' archetype the resultant JAR file following a build runs. As a project grows we find that sometimes the JAR won't run from the command line. Some Maven POM edits have been needed to 'encourage' the program to run from the command line again. This applies to Linux and Windows.
This also happens directly with the ZenJava JavaFX archetype, e.g. a project artifactId=xx:
java -jar target\xx.jar
no main manifest attribute, in target\xx.jar
This is just from the mavan generate command. The details of the two archetypes in question are:
zenjava
archetypeArtifactId=javafx-basic-archetype
archetypeGroupId=com.zenjava
netbeans
archetypeArtifactId=javafx
archetypeGroupId=org.codehaus.mojo.archetypes
Comparing the resulting POM files shows these that the codehaus.mojo (netbeans) uses these plugins in the build:
maven-dependency-plugin
maven-compiler-plugin
exec-maven-plugin
Either project runs happily from within Netbeans IDE. The challenges occur when we want to test on command line. It isn't really the best look externally when the build looks unstable to outsiders like that.
The questions arising are about what are the requirements to make a JavaFX command-line executable JAR file? For JDK 8 and beyond.
Is there an alternative JavaFX archetype available that will build projects with dependent JAR-s and run from the command line?
What allows Netbeans (say) to execute JAR when the same the built JAR won't run on the command-line?
What 'magic' does Netbeans be add to the execute step?
What is needed for the zenjava archetype to run "Java -jar"?
The JAR resulting from the follow steps doesn't run on the console.
mvn archetype:generate -DarchetypeGroupId=com.zenjava -DarchetypeArtifactId=javafx-basic-archetype ... -DartifactId=xx
mvn install
java -jar target/xx-001.jar
What influences the: maven-dependency-plugin and maven-compiler-plugin when building the JAR for bigger projects?
In other words, what assumptions might be being broken a project grows and bind with other JAR files.
Needless to say, the Maven generate and build steps are using the JDK Java environment. The execution though, java -jar target/xx-001.jar, need to run under the simple JRE (without the JDK). I guess question #4 is a long stretch unless you are someone who has a biggish JavaFX project and solved this already. Suggestions welcome.
just to mention: I'm the maintainer of the javafx-maven-plugin (and the archetype).
To answer your question 3:
You have to call the GENERATED jar-file from the plugin, which is located at target/jfx/app/yourapp.jar
The generated jar-file will reference all required dependencies, which are noted inside the META-INF/MANIFEST.MF-file inside it. While creating that jar-file, the pom is scanned for runtime-dependencies, these will be placed at the target/jfx/app/lib-folder. When bundling your app into native bundle, the JRE is put aside of the generated launcher under the target/jfx/native/-folder.
What confuses me about your problem: mixing CLI- and GUI-application might result in problems, but i guess it's just your special requirement :)
EDIT:
Calling mvn install does NOT generate jfx-jar without special configuration, you have to call mvn jfx:jar or mvn jfx:native to call the MOJOs of the plugin. For easier configuration, please visit our configuration-website: http://javafx-maven-plugin.github.io/
I recently found the library Libsodium and was glad that there are also Bindings for Java. Unfortunately, the libraries don't appear to work with Windows because they were developed for other systems.
How can I use the libraries under Windows (if possible)?
Are there any alternative libraries for Java?
On that page for other bindings, you find the Java binding is called Kalium. You'll see it requires Apache Maven. So I went and got that (at the bottom it explains how to install maven, but basically you just add some environment variables).
Now on to kalium, I got it from their abstract on github. I needed mvn clean install from the directory in order to install it in Maven. After changing directory to the unzipped Kalium folder I ran the specified command (which is telling Maven to get the files and install Kalium). This will handle the rest of the set-up.
Then it's just a matter of adding it as a dependency in your Maven projects as per the Kalium readme. As for libsodium: it is a library that works with MinGW, and VisualStudio in Windows. So if you want to do C/C++ coding you can use that instead. But for the Java binding it seems you'll have deploy it using Maven.
Java newbie here. I'm trying to run the latest version of MWDumper, which is a command-line utility that imports wiki databases. The page said I should build it from its source. I've downloaded the source-code. They've got a makefile and a build.xml. How do I build this?
You need to install ANT and run ANT in the folder containing the build.xml.
If you're on linux or mac it's pretty easy - you just [package manager name here] install ant;
You then just cd to the appropriate folder and type in ant. It should build your app.
You also need to make sure that you have the Java Development Kit installed for the ANT to use. Ant doesn't actually do any compiling, it's just a tool that reads build instructions and calls various applications and compilers to output the end executable (or similar product).
You should be able to install 'jdk' from your package manager, or from their site (http://www.oracle.com/technetwork/java/javase/downloads/index.html).
If you're on Windows, you can install the JDK from the same link, and you can follow the following link as a guide to install ant for windows: http://ant.apache.org/manual/install.html
Don't forget to add the path to ant to your environment 'PATH' variable! :) (more details in the link above)
Use Apache Ant.
cd <dir>
ant <target>
Also you can use Apache Maven.
cd <dir>
mvn install