I am trying to compile some Clojure code to Java using the Clojure 1.2 compiler. I am including the Clojure and Clojure-contrib 1.2 jars in the classpath. When I do the compile it fails and I get the folowing error:
Exception in thread "main" java.lang.ClassNotFoundException: clojure.contrib.io.Streams (io.clj:121)
: Has anyone seen this before?
Update:
Here is the line I use to compile my clj files:
java -cp "..\lib\h2.jar;..\lib\vaadin-6.4.4.jar;..\lib\clojure.jar;..\lib\clojure-contrib.jar;..\lib\wlfullclient-10.3.0.0.jar;..\..\..\..\..\jre1.6windows32bit\lib\rt.jar;." -Dclojure.compile.path=cljclasses clojure.lang.Compile oe.main.oe-main
clojure.contrib.io.Streams is a protocol defined in clojure.contrib.io
To help you more you have to share more details about how and what you are trying to compile.
use (compile 'oe.main.oe-main) from a clojure REPL using the same class path, and this works
Related
before I start, you probably need to know three things:
I don't have Java background
I'm a Clojure newbie - started to learn it
question is related to my "training" package kennyfy
TL;DR version I'm not able to import/use my training package in a project
Longer version
I set myself a goal - write simple API which converts text to kennyspeak. Before that I've created a package (using default lein template).
I tried to import this package to my API.
Part of project.clj looks like this:
:repositories [["jitpack" "https://jitpack.io"]]
:dependencies [[com.github.radmen/clojure-kennyfy "0.1.2"]]
lein deps fetches the package without any problems.
When I try to use it, Clojure fails with following message:
kennyfy-api.core=> (radmen.kennyfy/kenny-speak "foo")
ClassNotFoundException radmen.kennyfy java.net.URLClassLoader.findClass (URLClassLoader.java:382)
I understand the error, yet I've no idea why this class is not imported.
I am quite sure, that this may be related to the metadata stored in the package, which results in failed imports.
What am I doing wrong?
Thank you
$ java -version
openjdk version "1.8.0_192"
OpenJDK Runtime Environment (build 1.8.0_192-b26)
OpenJDK 64-Bit Server VM (build 25.192-b26, mixed mode)
$ lein version
Leiningen 2.8.3 on Java 1.8.0_192 OpenJDK 64-Bit Server VM
Clojure 1.9.0
A clojure namespaces is loaded the first time it is required.
foo.core=> (radmen.kennyfy/kenny-speak "foo")
Execution error (ClassNotFoundException) at java.net.URLClassLoader/findClass (URLClassLoader.java:382).
radmen.kennyfy
foo.core=> (require '[radmen.kennyfy :as kennyfy])
nil
foo.core=> (kennyfy/kenny-speak "foo")
"mpfppfppf"
foo.core=> (radmen.kennyfy/kenny-speak "foo")
"mpfppfppf"
foo.core=>
When I add :repl-options {:init (print "x..")} to ~/.lein/profiles.clj it does what it should on every repl start-up. however, when I add the same to my local project.clj, I receive this error:
Exception in thread "main" java.lang.RuntimeException: Unable to resolve symbol: do in this context, compiling:(/tmp/form-init5885833654225579206.clj:1:886)
I'm using leiningen 2.5.3
I've stumbled across this issue as well - I tried to use multiple profiles, each with its own :repl-options.
The issue is that Leiningen doesn't merge `:init: correctly. You can refer to this issue for more details.
Unfortunately, I couldn't find any fix that would work for me. And the issue itself won't be fixed till Leiningen 3.0.
I am new to JNI and swig and I'm trying to access AMD's ADL-SDK v6 from clojure but am running into some errors.
;; Clojure 1.5.1
=> (com.vnetpublishing.swig.adl.AdapterInfo.)
UnsatisfiedLinkError com.vnetpublishing.swig.adl.adlsdkJNI.new_AdapterInfo()J com.vnetpublishing.swig.adl.adlsdkJNI.new_AdapterInfo (adlsdkJNI.java:-2)
=> (System/loadLibrary "libatiadlxx")
UnsatisfiedLinkError no libatiadlxx in java.library.path java.lang.ClassLoader.loadLibrary (ClassLoader.java:1886)
The swig template is as follows
/* File jadl-sdk.i */
%module adlsdk
%{
#include "adl_sdk.h"
%}
%include "adl_defines.h"
%include "adl_structures.h"
%include "adl_sdk.h"
The classes were generated with the following command
swig -java -package com.vnetpublishing.swig.adl -v -DLINUX -I${JAVA_HOME}/include -I${JADL_PATH}/ADL_SDK/include -outdir ${PACKAGE_PATH} jadl-sdk.i
Does anyone know how to get this to function?
-edit-
I have been able to get this to partially function using
(clojure.lang.RT/loadLibrary "atiadlxx")
(clojure.lang.RT/loadLibrary "jadlsdk")
The only problem is the jadlsdk library isn't on the java.library.path , it is inside a jar, and I can't get it to load from leiningen.
I have solved the problem. The solution was to run the loadLibrary call as part of the static constructor and to install the swig generated wrapper library as a system library (On linux under /usr/lib).
The complete code is available on github at https://github.com/rritoch/WarpCTL/tree/master/extra/JADL-SDK
Once the wrapper library has been installed, and the java wrapper code has been compiled to a jar it can be loaded in the project.clj under :resource-paths
The clojure side code can be accessed # https://github.com/rritoch/WarpCTL
Programmin Clojure by "Stuart Halloway" book talks about Lancet, Very first step is (use 'lancet) which is throwing some Exception,
Exception
user=> (use 'lancet)
java.io.FileNotFoundException: Could not locate lancet__init.class or lancet.clj
on classpath: (NO_SOURCE_FILE:0)
Is any jar file or some package is required to make this work?
You need lancet installed to use lancet. I'm surprised the book doesn't mention anything like that. Anyway, I would strongly recommend you use leiningen instead. Lancet is out of date and leiningen is the most popular build tool for clojure these days.
user=> (use '[clojure.contrib.duck-streams])
java.io.FileNotFoundException: Could not locate clojure/contrib/duck_streams__in
it.class or clojure/contrib/duck_streams.clj on classpath: (NO_SOURCE_FILE:0)
Clojure.contrib is in CLASSPATH still it is throwing Exception. Do I need some other Jar?
Use clojure.java.io instead, it's included with 1.2.
I highly recommend using leiningen to sort this out.
try the lein repl command to get a quick repl with a working classpath.
According to this message:
http://osdir.com/ml/clojure/2010-10/msg00834.html
clojure.contrib.duck-streams has been deprecated.