“java.io.filenotfoundexception”错误,与作为函数参数的端口号8080相关

olmpazwi  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(303)

我正在练习clojure教程“基本web开发”http://clojure-doc.org/articles/tutorials/basic_web_development.html
最后,我面临一个问题。当我执行

$ java -jar target/clojure-webapp-0.1.0-SNAPSHOT-standalone.jar 8080

发生错误

Exception in thread "main" java.io.FileNotFoundException: 8080 (No such file or directory)

因此,端口号被解析为找不到的文件的文件名。
我不熟悉java,但我认为情况很清楚。端口号是一个典型的函数参数,而不是文件名。请给我解释一下,告诉我怎么修。更多详细信息:

s@lokal:~/Dropbox/clojure-webapp$ lein uberjar
Created /home/s/Dropbox/clojure-webapp/target/clojure-webapp-0.1.0-SNAPSHOT.jar
Created /home/s/Dropbox/clojure-webapp/target/clojure-webapp-0.1.0-SNAPSHOT-standalone.jar
s@lokal:~/Dropbox/clojure-webapp$ cat ~/Dropbox/clojure-webapp/src/clojure_webapp/handler.clj 
(ns clojure-webapp.handler
  (:require [clojure-webapp.views :as views]
            [compojure.core :refer :all]
            [compojure.route :as route]
            [ring.adapter.jetty :as jetty]
            [ring.middleware.defaults :refer [wrap-defaults site-defaults]])
  (:gen-class))
(defroutes app-routes ; replace the generated app-routes with this
  (GET "/"
       []
       (views/home-page))
  (GET "/add-location"
       []
       (views/add-location-page))
  (POST "/add-location"
        {params :params}
        (views/add-location-results-page params))
  (GET "/location/:loc-id"
       [loc-id]
       (views/location-page loc-id))
  (GET "/all-locations"
       []
       (views/all-locations-page))
  (route/resources "/")
  (route/not-found "Not Found"))

(def app
  (wrap-defaults app-routes site-defaults))

(defn -main
  [& [port]]
  (let [port (Integer. (or port
                           (System/getenv "PORT")
                           5000))]
    (jetty/run-jetty #'app {:port  port
                            :join? false})))
s@lokal:~/Dropbox/clojure-webapp$ java -jar target/clojure-webapp-0.1.0-SNAPSHOT-standalone.jar 8080
Exception in thread "main" java.io.FileNotFoundException: 8080 (No such file or directory)
    at java.base/java.io.FileInputStream.open0(Native Method)
    at java.base/java.io.FileInputStream.open(FileInputStream.java:219)
    at java.base/java.io.FileInputStream.<init>(FileInputStream.java:157)
    at java.base/java.io.FileInputStream.<init>(FileInputStream.java:112)
    at clojure.lang.Compiler.loadFile(Compiler.java:7449)
    at clojure.main$load_script.invokeStatic(main.clj:278)
    at clojure.main$script_opt.invokeStatic(main.clj:338)
    at clojure.main$script_opt.invoke(main.clj:333)
    at clojure.main$main.invokeStatic(main.clj:424)
    at clojure.main$main.doInvoke(main.clj:387)
    at clojure.lang.RestFn.applyTo(RestFn.java:137)
    at clojure.lang.Var.applyTo(Var.java:702)
    at clojure.main.main(main.java:37)
s@lokal:~/Dropbox/clojure-webapp$
nkoocmlb

nkoocmlb1#

我想这个教程有点老了。不管怎样,使用底座而不是戒指你可能会更开心。您可以在此处找到“hello world”教程:
http://pedestal.io/guides/hello-world
我有一些工作代码是教程的结果,您可以从这里克隆:

git@github.com:cloojure/pedestal-tutorial.git

在终端窗口中,通过以下方式启动代码:

> lein run

然后将浏览器导航到:

http://localhost:8890/echo                   ; demo/test route
http://localhost:8890/greet                  ; generic greeting
http://localhost:8890/greet?name=Bob         ; normal greeting
http://localhost:8890/greet?name=Voldemort   ; unmentionable!

如果你想坚持使用ring/compojure,另一个选择是clojure食谱,它有很多例子。可打印(推荐)或在线获取:
https://github.com/clojure-cookbook/clojure-cookbook/tree/master/07_webapps
下面是另一本好书:
clojure中的web开发

相关问题