MYOB ODBC 驱动程序使用 Compojure 将工作目录更改为临时目录

发布于 2024-09-27 16:51:34 字数 959 浏览 4 评论 0原文

我编写了一个内部 web 应用程序,用于将工作卡数据库中的发票导入到 MYOB 中。我使用 Clojure 和 Compojure 编写了它,它实际上运行得很好,这对我来说也是一个很好的学习练习。

但是,我遇到了一个问题,似乎在成功导入发票后,jetty 服务器将不再提供静态 CSS 文件。

defroute如下:(

(defroutes static-routes
  (GET ["/:filename" :filename #".*"] [filename]
       (response/file-response filename {:root "public"})))

该文件只是css/default.css,在第一次导入之前它工作得很好。)

现在我想我已经找到问题了,看来MYOB ODBC驱动程序正在更改的工作目录Jetty 服务器(和我的 REPL),因为当我在 REPL 中输入以下内容时:

(file-seq (File. "."))

我得到了我的临时文件目录的列表,这可以解释为什么不再找到我的 CSS 文件。

奇怪的是,如果我这样做:

(.getAbsolutePath (File. "."))

我会得到应用程序的正确目录。

有谁知道有什么东西(除了在绝对路径中编码之外)可以解决 MYOB ODBC 驱动程序的这个怪癖?

我猜我可以在启动时获取并存储绝对路径,但这适用于 uberjar 吗?

编辑: 由于JVM的限制,似乎无法修复?

如何使用 Clojure 在命令行中更改目录?< /a>

I've written a little internal webapp that I use to import invoices from our jobcard database into MYOB. I've written it using Clojure and Compojure, and it actually works pretty well, and it was also a good learning exercise for me.

However, I've got a problem, it seems that after a successful invoice import the jetty server will no longer serve the static CSS file.

The defroute is as follows:

(defroutes static-routes
  (GET ["/:filename" :filename #".*"] [filename]
       (response/file-response filename {:root "public"})))

(The file is just css/default.css, it works just perfectly before the first import.)

Now I think I've found the problem, it seems that the MYOB ODBC driver is changing the working directory of the Jetty server (and my REPL), because when I enter the following in the REPL:

(file-seq (File. "."))

I get a listing of my Temp files directory, which would explain why my CSS file is no longer being found.

The odd thing is, if I do:

(.getAbsolutePath (File. "."))

I get the correct directory of my application.

Does anyone know of something (other than coding in an absolute path) that can get around this quirk of the MYOB ODBC driver?

I'm guessing that I could just grab and store the absolute path when I start up, but would that work with an uberjar?

Edit:
It seems that it is impossible to fix due to limitations in the JVM?

How do I change directory in command line with Clojure?

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

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

发布评论

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

评论(1

∞琼窗梦回ˉ 2024-10-04 16:51:34

对此似乎确实没有什么可做的。看来 MYOB ODBC 桥很糟糕。

因此,为了解决这个问题,我将相关文件调用替换为使用 .getAbsolutePath。

例如,

(java.io.File. (.getAbsolutePath (java.io.File. "templates/index.html")))

我还更改了它,以便静态文件请求使用绝对文件路径:

(defroutes static-routes
  (GET ["/:filename" :filename #".*"] [filename]
       (response/file-response filename {:root (.getAbsolutePath (java.io.File. "public"))})))

我不只是尝试创建 uberjar,所以我预计可能会遇到一些问题。


只是对此进行更新,使用 Compojure 的资源功能似乎完全跳过了问题,在创建 UberJar 时也没有问题。

所以我不再定义“静态路由”,我只是使用:

 (route/resources "/")

并将资源/公共目录中的文件放在项目的根目录中。

There doesn't really seem to be much that can be done about this. It just seems that the MYOB ODBC bridge is just bad.

So in order to get around this, I've replaced my relative file calls to use .getAbsolutePath.

e.g.

(java.io.File. (.getAbsolutePath (java.io.File. "templates/index.html")))

I've also changed it so static file requests use a absolute file path:

(defroutes static-routes
  (GET ["/:filename" :filename #".*"] [filename]
       (response/file-response filename {:root (.getAbsolutePath (java.io.File. "public"))})))

I haven't just tried creating an uberjar, so I expect I might get some problems there.


Just an update to this, using Compojure's resources function seems to skip with problem entirely, also working without problems when creating an UberJar.

So I no longer have "static-routes" defined anymore, I just use:

 (route/resources "/")

And have the files in my resources/public directory in the root directory of my project.

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