weavejester / compojure

A concise routing library for Ring/Clojure
Eclipse Public License 1.0
4.08k stars 259 forks source link

"lein ring server" in WSL - Can i configure the browser behavior? #190

Closed supernovae closed 3 months ago

supernovae commented 4 years ago

Windows 10, Windows Subsystem for Linux.

I run "lein ring server" and it fails because i don't have an DISPLAY set up to launch a default browser. Is there a way to make lein aware of WSL and have it use OS Browser somehow?

Or a way to change the behavior of it so it won't throw so many errors on startup? (not open browser by default)

2019-10-30 17:10:22.178:INFO::main: Logging initialized @1920ms 2019-10-30 17:10:25.847:INFO:oejs.Server:main: jetty-9.2.21.v20170120 2019-10-30 17:10:25.897:INFO:oejs.ServerConnector:main: Started ServerConnector@32e736a7{HTTP/1.1}{0.0.0.0:3000} 2019-10-30 17:10:25.899:INFO:oejs.Server:main: Started @5641ms Started server on port 3000 Exception in thread "main" Syntax error compiling at (/tmp/form-init8347044386782256737.clj:1:73). at clojure.lang.Compiler.load(Compiler.java:7647) at clojure.lang.Compiler.loadFile(Compiler.java:7573) at clojure.main$load_script.invokeStatic(main.clj:452) at clojure.main$init_opt.invokeStatic(main.clj:454) at clojure.main$init_opt.invoke(main.clj:454) at clojure.main$initialize.invokeStatic(main.clj:485) at clojure.main$null_opt.invokeStatic(main.clj:519) at clojure.main$null_opt.invoke(main.clj:516) at clojure.main$main.invokeStatic(main.clj:598) at clojure.main$main.doInvoke(main.clj:561) at clojure.lang.RestFn.applyTo(RestFn.java:137) at clojure.lang.Var.applyTo(Var.java:705) at clojure.main.main(main.java:37) Caused by: java.awt.HeadlessException: No X11 DISPLAY variable was set, but this program performed an operation which requires it. at java.desktop/java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:208) at java.desktop/java.awt.Window.(Window.java:548) at java.desktop/java.awt.Frame.(Frame.java:423) at java.desktop/java.awt.Frame.(Frame.java:388) at java.desktop/javax.swing.JFrame.(JFrame.java:180) at clojure.java.browse_ui$open_url_in_swing.invokeStatic(browse_ui.clj:19) at clojure.java.browse_ui$open_url_in_swing.invoke(browse_ui.clj:15) at clojure.lang.Var.invoke(Var.java:384) at clojure.java.browse$open_url_in_swing.invokeStatic(browse.clj:64) at clojure.java.browse$browse_url.invokeStatic(browse.clj:74) at clojure.java.browse$browse_url.invoke(browse.clj:66) at ring.server.standalone$open_browser_to.invokeStatic(standalone.clj:38) at ring.server.standalone$open_browser_to.invoke(standalone.clj:37) at ring.server.standalone$serve$fn__4182.invoke(standalone.clj:107) at ring.server.standalone$try_port.invokeStatic(standalone.clj:16) at ring.server.standalone$try_port.invoke(standalone.clj:10) at ring.server.standalone$serve.invokeStatic(standalone.clj:100) at ring.server.standalone$serve.doInvoke(standalone.clj:75) at clojure.lang.RestFn.invoke(RestFn.java:423) at ring.server.leiningen$serve.invokeStatic(leiningen.clj:19) at ring.server.leiningen$serve.invoke(leiningen.clj:16) at user$eval6785.invokeStatic(form-init8347044386782256737.clj:1) at user$eval6785.invoke(form-init8347044386782256737.clj:1) at clojure.lang.Compiler.eval(Compiler.java:7176) at clojure.lang.Compiler.eval(Compiler.java:7166) at clojure.lang.Compiler.load(Compiler.java:7635) ... 12 more

supernovae commented 4 years ago

obviously i can open a browser and go to localhost:3000 :) but figured i'd ask if there was a way to clean this up (i'm a total newb with this stuff)

fedja-tica commented 4 years ago

There are three things you can do, either of which could solve the issue.

  1. Add :jvm-opts ["-Djava.awt.headless=true"] to your project.clj. This prevents the JVM from searching for an X server.
  2. Install an X server on the Windows end and configure WSL to use it.
  3. Start your application with lein ring server-headless. This way, ring-server won't try to open a browser window.

IMO, number 3 might be your best bet: number 2 is a bit of an overkill and number 1 is something I've run into myself while attempting to run an app inside a Docker container.

Huarastaca commented 1 year ago

none of them worked and i tried doing with this project (https://gitlab.com/programacaofuncional/financeiro) can someone else pls try it for me bc i can be my machine