Iam trying for HOURS now and cant figure out the problem.
Iam new to clojure and try to make a simple flickr client.
But I have this problem with different libraries... I think I make a general mistake.
At the moment I try to use oauth with this lib: https://github.com/mattrepl/clj-oauth
lein new projectname
and my project.clj looks like this:
(defproject flickr "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.4.0"]
[clj-oauth "1.4.0"]])
After adding the clj-oauth2 I run:
lein deps
And my core.clj:
(ns flickr.core)
(require ['oauth.client :as 'oauth])
(def consumer-key "0000")
(def consumer-secret "0000")
(def consumer (oauth.client/make-consumer <consumer-token>
<consumer-token-secret>
"http://www.flickr.com/services/oauth/request_token"
"http://www.flickr.com/services/oauth/access_token"
"http://www.flickr.com/services/oauth/authorize"
:hmac-sha1))
When I now try to run it:
lein run
I get:
FileNotFoundException Could not locate oauth/client__init.class or oauth/client.clj on classpath: clojure.lang.RT.load (RT.java:432)
Does anyone has an idea where the problem is?
Also also downloaded the oauth source from the github repo, built it and added it to my $PATH variable but still the same error.
Any help would be appreciated!
Thanks!
First, lein run looks for a main namespace, whose name must be specified in project.clj using the :main key; add :main flickr.core there.
Then you need a -main function in flickr.core. Change your namespace declaration and add the function as follows:
(ns flickr.core
(:require [clj-oauth2.client :as oauth]))
(defn -main []
(println oauth/get-access-token))
Then,
$ lein run
;=> #<client$get_access_token clj_oauth2.client$get_access_token#4c9549af>
That worked for me as a sort of "namespace smoke test," and you should be able to go from there.
(As a final note, your development will go much faster if you test these sorts of things in the REPL rather than using 'lein run.')
It appears there's confusion with your dependencies. According to Clojars, the library you're using clj-oauth2 is this GitHub project https://github.com/DerGuteMoritz/clj-oauth2, not the one you link to in the question.
If you want the latest clj-oauth, then the dependency should be [clj-oauth "1.4.0"] (for the latest version). If you need clj-oauth2 then the above GitHub link should be the reference.
Related
Trying to use Thomas Petriek's build script: https://github.com/tpetricek/suave-xplat-gettingstarted/blob/master/build.fsx
Getting error that the namespace Types is not defined in open Suave.Types.
Is this some namespace that has since been deprecated?
I am not sure if that is an old version of the build script, but I am using the same build script myself, I had to make a couple of changes namely, remove the logging, use
open Suave.Http
instead of
open Suave.Types
and use these bindings
bindings = [ HttpBinding.create Protocol.HTTP Net.IPAddress.Loopback 8083us ]
I can't figure out how to automatically start an "deps" applciation in Chicago Boss.
Use applcation:which_applications() I can see a bunch started like "lager, ranch, cowboy ..etc etc". How do I start another one I added?
If I go to console and run application:start(oauth2) and it's ok. I can start it.
But I tried to change src/xxx.app.src and add it to {applications,[]}, but no go. Isn't this the place to load/start any application that mine depends on?
But I can't find how boss loads and start all the other applications either.
By the way, this oauth2 appliation doesn't contain an application-behavior file (oauth2_app.erl) so I don't know if this is related. Since I can manually start it ok.
So, confused. Any help would be appreciated.
Plus: I remember that I did start application by adding the application:start(xxx) into the /priv/init/xxx_01_news.erl init function but that's very hackish I think.
You can use rebar.config to add your dependency applications then edit boss.config file this way:
First: Add the dependency applications name in applications.
Second: Add their specific configurations as follows.
boss.config file:
[
{boss, [
{path, "./deps/boss"},
{applications, [your_app_name, your_app_dep_1, your_app_dep_2]},
{assume_locale, "en"},
%% ... other configuration
%% APPLICATION CONFIGURATIONS
{your_app_name, []},
{your_app_dep_1, []},
{your_app_dep_2, []}
].
Edit: This way CB expects another boss application so looks for the router file and warns if cannot find it. However starting the dependencies inside its init function is not a dirty way and I suggest to consider it.
I'm connected to an Erlang node with -remsh. How do I modify the code path, in order to load a library that wasn't packaged into my release?
All necessary functions to manipulate code loading, path... are in the code module (see doc at erlang otp code module).
You could add the system paths to the list by doing the following:
[code:add_pathz(P) || P <- filelib:wildcard("/usr/lib/erlang/lib/*/ebin")].
After compiling some test code and connecting to a running node I was able to make it work with this:
(app#127.0.0.1)1> code:add_pathz("/path/to/my/compiled/beam").
(app#127.0.0.1)2> tester:hi().
hi!
ok
(app#127.0.0.1)3>
I am trying to run xUnit tests (from an F# module, if it makes any difference) using TestDriven.NET, but whatever I do I get this error:
It looks like you're trying to execute an xUnit.net unit test.
For xUnit 1.5 or above (recommended):
Please ensure that the directory containing your 'xunit.dll' reference also contains xUnit's
test runner files ('xunit.dll.tdnet', 'xunit.runner.tdnet.dll' etc.)
For earlier versions:
You need to install support for TestDriven.Net using xUnit's 'xunit.installer.exe' application.
You can find xUnit.net downloads and support here:
http://www.codeplex.com/xunit
I tried following the suggestions, i.e. I copied the files
xunit.dll.tdnet
xunit.extensions.dll
xunit.gui.clr4.exe
xunit.runner.tdnet.dll
xunit.runner.utility.dll
xunit.runner.utility.xml
xunit.xml
to the folder with xunit.dll and I ran xunit.installer.exe. How can I get it to work?
I just figured out that I forgot to make the test a function in F# (so it was just a value). The error message can't be more misleading though!
You have two problems:
your Fact is broken:-
If you hover over the
please work
bit, you'll see something like: unit -> int
For a Fact to be picked up by an xUnit runner, it needs to yield `unit (void).
Hence, one key thing to get right first is to not return anything. In other words, replace your 123 with () (or an Assertion).
You can guard against this by putting a :unit stipulation on the test:-
[<Fact>]
let ``please work`` () : unit = 123
This will force a compilation error.
TestDriven.NET is reporting it cannot find the xunit.tdnet modules
It's critical to get step 1 right first. Then retry and the problem should be gone
If it remains...
Either try the VS-based runner which should work as long as it's installed and xunit.dll is getting to your output dir or look at the docs for your version of TD.NET for detailed troubleshooting notes (exec summary is if the .tdnet file was in your out dir or you undo and redo the xunit.installer from the folder containing the packages it should just work, esp if you are on latest)
In Java there's a simple way to get path of a running jar file:
MyClass.class.getProtectionDomain().getCodeSource().getLocation().getPath()
But in Clojure we do not have class name, only namespace and functions. Same thing applies to the uncompiled scripts/REPL.
So my questions are:
How can we find a path to the running jar file?
How can we find a path to uncompiled source files?
By default the name of your class is the name of your AOT-compiled namespace (that's what gen-class is for), so you can simply use the namespace's class.
(ns foo.core
(:gen-class))
(defn this-jar
"utility function to get the name of jar in which this function is invoked"
[& [ns]]
;; The .toURI step is vital to avoid problems with special characters,
;; including spaces and pluses.
;; Source: https://stackoverflow.com/q/320542/7012#comment18478290_320595
(-> (or ns (class *ns*))
.getProtectionDomain .getCodeSource .getLocation .toURI .getPath))
(defn -main [& _]
(println (this-jar foo.core)))
Result of running:
$ java -cp foo-0.1.0-SNAPSHOT-standalone.jar foo.core
/home/rlevy/prj/foo/target/foo-0.1.0-SNAPSHOT-standalone.jar
The idea of classpath is to hide where classes come from. You may have classes with the same name loaded from different classloaders, you may have the same class in multiple jars and rely on classpath ordering to choose the correct one.
Why do you want to know? If it's for any other reason than debug/logging purposes you are on dangerous ground and should tread carefully.
In fact it's perfectly reasonable for classes to have no jar file. This can happen in java for any runtime generated classes (think proxies).
In clojure a simple example would be as shown in the repl session below... You'll see #mikera's suggestion works fine for clojure.lang.Atom which is a built in class. But when you use a deftype to create your own type, clojure generates a class and it has no location...
user> (prn (-> clojure.lang.Atom
(.getProtectionDomain)
(.getCodeSource)
(.getLocation)))
#<URL file:/workspace/clj-scratch/lib/clojure-1.3.0.jar>
nil
user> (deftype Foo [])
user.Foo
user> (prn (-> (Foo.)
(.getClass)
(.getProtectionDomain)
(.getCodeSource)
(.getLocation)))
nil
nil
user>
I haven't tried this, but it seems like all you need is a class instance. So for example can you not do this:
(-> (new Object) (.getClass) (.getProtectionDomain) (.getCodeSource) (.getLocation) (.getPath))
You could try getting the path from a class defined by Clojure itself, e.g.:
(-> clojure.lang.Atom (.getProtectionDomain) (.getCodeSource) (.getLocation))
=> file:/some/path/to/clojure-1.3.0.jar
I believe this is technically the running jar file if you are running Clojure scripts or coding at the REPL.
(defn this-jar
"utility function to get the name of jar in which this function is invoked"
[& [ns]]
(-> (or ns (class *ns*))
.getProtectionDomain .getCodeSource .getLocation .toURI .getPath))
Note that it's crucial to call .toURI to avoid problems with paths that have spaces as described in the equivalent Java question: How to get the path of a running JAR file?.
find source files in a jar: tools.namespace/clojure-sources-in-jar