无法在lein repl中导入java类

时间:2014-06-05 18:35:16

标签: java clojure leiningen read-eval-print-loop

尝试使用lein在clojure项目中导入java类,然后使用main方法连接到TeamworkPM的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位于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);

然后我在正确的项目中启动苹果酒......

teamwork.core> (TeamworkAPI. new)

CompilerException java.lang.RuntimeException: Unable to resolve symbol: new in
   this context, compiling:(/tmp/form-init133047100967026670.clj:1:1) 

尝试通过我与外国API的第一次连接来弄清楚:)

1 个答案:

答案 0 :(得分:0)

通过互操作制作对象的语法是(TeamworkAPI.),或者较早的(new TeamworkAPI)

如果你打算打电话给那个班级'静态主要方法:(TeamworkAPI/main (into-array args))