appengine magic,几乎满意,但在 repl 上得到空指针

发布于 2024-10-30 05:35:57 字数 3249 浏览 2 评论 0原文

我让 webapp(用 appengine-magic 和 lein 制作)在 dev_appserver.sh 上工作,但因为我需要更多的交互性和更少的重新启动服务器,所以我更喜欢使用 repl。现在的问题是,在我执行 (require '[appengine-magic.core :as ae])(use 'myapp.core) 并尝试提供应用程序< code>(ae/serve myapp) 我得到这个异常:

[Thrown class java.lang.NullPointerException]

Backtrace:
  0: java.io.File.<init>(File.java:360)
  1: sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  2: sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
  3: sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
  4: java.lang.reflect.Constructor.newInstance(Constructor.java:513)
  5: clojure.lang.Reflector.invokeConstructor(Reflector.java:160)
  6: appengine_magic.core$start.doInvoke(core_local.clj:85)
  7: clojure.lang.RestFn.invoke(RestFn.java:439)
  8: appengine_magic.core$serve.doInvoke(core_local.clj:139)
  9: clojure.lang.RestFn.invoke(RestFn.java:410)
 10: user$eval2264.invoke(NO_SOURCE_FILE:1)
 11: clojure.lang.Compiler.eval(Compiler.java:5424)
 12: clojure.lang.Compiler.eval(Compiler.java:5391)
 13: clojure.core$eval.invoke(core.clj:2382)
 14: swank.commands.basic$eval_region.invoke(basic.clj:47)
 15: swank.commands.basic$eval_region.invoke(basic.clj:37)
 16: swank.commands.basic$eval807$listener_eval__808.invoke(basic.clj:71)
 17: clojure.lang.Var.invoke(Var.java:365)
 18: user$eval2262.invoke(NO_SOURCE_FILE)
 19: clojure.lang.Compiler.eval(Compiler.java:5424)
 20: clojure.lang.Compiler.eval(Compiler.java:5391)
 21: clojure.core$eval.invoke(core.clj:2382)
 22: swank.core$eval_in_emacs_package.invoke(core.clj:92)
 23: swank.core$eval_for_emacs.invoke(core.clj:239)
 24: clojure.lang.Var.invoke(Var.java:373)
 25: clojure.lang.AFn.applyToHelper(AFn.java:167)
 26: clojure.lang.Var.applyTo(Var.java:482)
 27: clojure.core$apply.invoke(core.clj:540)
 28: swank.core$eval_from_control.invoke(core.clj:99)
 29: swank.core$eval_loop.invoke(core.clj:104)
 30: swank.core$spawn_repl_thread$fn__493$fn__494.invoke(core.clj:309)
 31: clojure.lang.AFn.applyToHelper(AFn.java:159)
 32: clojure.lang.AFn.applyTo(AFn.java:151)
 33: clojure.core$apply.invoke(core.clj:540)
 34: swank.core$spawn_repl_thread$fn__493.doInvoke(core.clj:306)
 35: clojure.lang.RestFn.invoke(RestFn.java:397)
 36: clojure.lang.AFn.run(AFn.java:24)
 37: java.lang.Thread.run(Thread.java:680)

我也尝试过 (in-ns 'myapp.core) 但效果相同。当我将 Web 应用程序处理程序直接粘贴到 repl 上并提供服务时,它可以工作,但不能从我的文件中粘贴。

调用 myapp 或 myapp-handler 清楚地给出了“对象”,所以我真的应该在正确的命名空间上...

project.clj

(defproject myapp "1.0.0-SNAPSHOT"
  :description "FIXME: write description"
  :dependencies [
        [org.clojure/clojure "1.2.1"]
        [compojure "0.6.2"]
        ]
  :dev-dependencies [
            [appengine-magic "0.4.1"]
            [ring/ring-devel "0.3.7"]
            ])

core.clj 就这么简单:

(ns myapp.core
    (:use compojure.core)
    (:require [appengine-magic.core :as ae]))

(defroutes myapp-handler
    (GET "/" req
       {:status 200
        :headers {"Content-Type" "text/plain"}
        :body "Hello, world!!!"}))

(ae/def-appengine-app myapp #'myapp-handler)

I got webapp (made with appengine-magic and lein) working on dev_appserver.sh but because I need more interactivity and less restarting the server I prefer to use repl. Now problem is, that after I do (require '[appengine-magic.core :as ae]), (use 'myapp.core) and try to serve application (ae/serve myapp) I get this exception:

[Thrown class java.lang.NullPointerException]

Backtrace:
  0: java.io.File.<init>(File.java:360)
  1: sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  2: sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
  3: sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
  4: java.lang.reflect.Constructor.newInstance(Constructor.java:513)
  5: clojure.lang.Reflector.invokeConstructor(Reflector.java:160)
  6: appengine_magic.core$start.doInvoke(core_local.clj:85)
  7: clojure.lang.RestFn.invoke(RestFn.java:439)
  8: appengine_magic.core$serve.doInvoke(core_local.clj:139)
  9: clojure.lang.RestFn.invoke(RestFn.java:410)
 10: user$eval2264.invoke(NO_SOURCE_FILE:1)
 11: clojure.lang.Compiler.eval(Compiler.java:5424)
 12: clojure.lang.Compiler.eval(Compiler.java:5391)
 13: clojure.core$eval.invoke(core.clj:2382)
 14: swank.commands.basic$eval_region.invoke(basic.clj:47)
 15: swank.commands.basic$eval_region.invoke(basic.clj:37)
 16: swank.commands.basic$eval807$listener_eval__808.invoke(basic.clj:71)
 17: clojure.lang.Var.invoke(Var.java:365)
 18: user$eval2262.invoke(NO_SOURCE_FILE)
 19: clojure.lang.Compiler.eval(Compiler.java:5424)
 20: clojure.lang.Compiler.eval(Compiler.java:5391)
 21: clojure.core$eval.invoke(core.clj:2382)
 22: swank.core$eval_in_emacs_package.invoke(core.clj:92)
 23: swank.core$eval_for_emacs.invoke(core.clj:239)
 24: clojure.lang.Var.invoke(Var.java:373)
 25: clojure.lang.AFn.applyToHelper(AFn.java:167)
 26: clojure.lang.Var.applyTo(Var.java:482)
 27: clojure.core$apply.invoke(core.clj:540)
 28: swank.core$eval_from_control.invoke(core.clj:99)
 29: swank.core$eval_loop.invoke(core.clj:104)
 30: swank.core$spawn_repl_thread$fn__493$fn__494.invoke(core.clj:309)
 31: clojure.lang.AFn.applyToHelper(AFn.java:159)
 32: clojure.lang.AFn.applyTo(AFn.java:151)
 33: clojure.core$apply.invoke(core.clj:540)
 34: swank.core$spawn_repl_thread$fn__493.doInvoke(core.clj:306)
 35: clojure.lang.RestFn.invoke(RestFn.java:397)
 36: clojure.lang.AFn.run(AFn.java:24)
 37: java.lang.Thread.run(Thread.java:680)

I have also tried (in-ns 'myapp.core) but same effect. When I paste web app handler straight on repl and serve then it works, but not from my file.

calling myapp or myapp-handler clearly gives the "object" so I should really be on right namespace...

project.clj

(defproject myapp "1.0.0-SNAPSHOT"
  :description "FIXME: write description"
  :dependencies [
        [org.clojure/clojure "1.2.1"]
        [compojure "0.6.2"]
        ]
  :dev-dependencies [
            [appengine-magic "0.4.1"]
            [ring/ring-devel "0.3.7"]
            ])

core.clj is as just simple:

(ns myapp.core
    (:use compojure.core)
    (:require [appengine-magic.core :as ae]))

(defroutes myapp-handler
    (GET "/" req
       {:status 200
        :headers {"Content-Type" "text/plain"}
        :body "Hello, world!!!"}))

(ae/def-appengine-app myapp #'myapp-handler)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

故笙诉离歌 2024-11-06 05:35:57

你用的是什么类型的repl?我已经复制了您的项目,但将

[swank-clojure "1.3.0-SNAPSHOT"]

添加到 :dev-dependency 中。使用 lein swank 命令启动 slime repl,然后使用 slime-connect 从 emacs 连接到它。然后我使用了与您相同的命令,即(需要'[appengine-magic.core:as ae]),(使用'myapp.core)和(ae/serve myapp)它工作正常。

干杯,
科林

What kind of repl are you using? I have replicated your project but added

[swank-clojure "1.3.0-SNAPSHOT"]

to the :dev-dependencies. Start a slime repl using the lein swank command and then use slime-connect to connect to it from from emacs. Then I used the same commands as you i.e. (require '[appengine-magic.core :as ae]), (use 'myapp.core) and (ae/serve myapp) it works fine.

Cheers,
Colin

甜嗑 2024-11-06 05:35:57

在调用(ae/serve myapp)之前尝试在项目文件夹中运行“lein clean”。

我遇到了类似的问题,我正在 AOT 编译导致问题的代码。我与 appengine-magic 的创建者讨论了这个问题,他建议通过运行 lein clean 来删除 AOT 编译的类,从而解决了这个问题。

try running "lein clean" in the project folder before calling (ae/serve myapp).

I had a similar problem where I was AOT compiling the code which was causing problems. I discussed this with the creator of appengine-magic and he suggested removing the AOT compiled classes by running lein clean which solved it.

浪推晚风 2024-11-06 05:35:57

此症状(java.io.File. 中的 NPE)也可能是由于错误地将处理程序 var 传递到 ae/serve 而不是创建的 var 引起的通过 def-appengine-app 宏。

This symptom (NPE in java.io.File.<init>) can also be caused by mistakenly passing e.g. the handler var to ae/serve rather than the var created by the def-appengine-app macro.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文