defproject编译器异常 [英] defproject Compiler Exception

查看:194
本文介绍了defproject编译器异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写由Stuart Halloway和Aaron Bedra编写的Clojure编程(第二版)。按照书中的说明,我在文件project.clj(由 lein new pinger 创建)中编辑和添加代码,如下所示:

I am working through the book Programming Clojure (Second Edition) by Stuart Halloway and Aaron Bedra. As instructed in the book, I edit and add code in the file project.clj (which was created by lein new pinger) so that it reads:

(defproject pinger "0.0.1-SNAPSHOT"
  :description "A website availability tester"
  :dependencies [[org.clojure/clojure "1.3.0"]])

(ns pinger.core
  (:import (java.net URL HttpURLConnection)))

(defn response-code [address]
  (let [conn ^HttpURLConnection (.openConnection (URL. address))
    code (.getResponseCode conn)]
    (when (< code 400)
      (-> conn .getInputStream .close))
    code))

然后尝试加载文件并得到以下错误:

I then try to load the file and get the following error:

user=> (load-file "src/pinger/project.clj") 
CompilerException java.lang.RuntimeException: Unable to resolve symbol: defproject 
in this context, compiling:(C:\Documents and Settings\vreinpa\My Documents\Books\ProgrammingClojure\code\src\pinger\project.clj:1)

我在这里做错了什么?

推荐答案

您不应该添加任何代码project.clj在defproject定义之外。

You're not supposed to add any code to the project.clj outside of the defproject definition.

真正的项目代码应该进入类路径(例如,在lein new .. 。in src)

The real project code is supposed to go into the classpath (for instance, in the files generated by "lein new ..." in src)

这篇关于defproject编译器异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆