Trying to import java classes in a clojure project using lein, and subsequently use the main method to connect to TeamworkPM's API. :)
project.clj
(defproject teamwork "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.5.1"]
[clj-http "0.9.2"]]
:resource-paths ["src/java/*"]
:java-source-paths ["src/java/"]
:javac-options ["-target" "1.6"
"-source" "1.6"
"-Xlint:-options"])
TeamworkAPI.java
is located in src/java/
.
public class TeamworkAPI {
public static void main(String[] args) {
HttpURLConnection connection = null;
String APIKey = "YOUR_API_KEY_HERE";
String TeamworkURL = "http://YOUR_TEAMWORKSITE_HERE.teamworkpm.net";
try {
URL url = new URL( TeamworkURL + "/projects.json" );
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
String userpassword = APIKey + ":" + "";
String encodedAuthorization = Base64Coder.encodeString( userpassword );
connection.setRequestProperty("Authorization", "Basic " + encodedAuthorization);
Then I fire up cider-jack-in on the correct project....
teamwork.core> (TeamworkAPI. new)
CompilerException java.lang.RuntimeException: Unable to resolve symbol: new in
this context, compiling:(/tmp/form-init133047100967026670.clj:1:1)
Trying to get my hands dirty with some of my first connectivity with foreign APIs :)
The syntax for making an object via interop is (TeamworkAPI.)
, or the older (new TeamworkAPI)
.
If you are trying to call that class' static main method: (TeamworkAPI/main (into-array args))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.