Lein ring server is not working fine within windows WSL

Stack trace seen upon running lein ring server within windows subsystem for linux.
Should I be using lein ring server-headless instead?

I am starting wsl.exe from vscode and opening a shell

No X11 DISPLAY variable was set, but this program performed an operation which requires it.

Retrieving ring/ring-servlet/1.6.1/ring-servlet-1.6.1.pom from clojars
Retrieving org/eclipse/jetty/jetty-server/9.2.21.v20170120/jetty-server-9.2.21.v20170120.pom from central
Retrieving org/eclipse/jetty/jetty-project/9.2.21.v20170120/jetty-project-9.2.21.v20170120.pom from central
Retrieving org/eclipse/jetty/jetty-parent/23/jetty-parent-23.pom from central
Retrieving org/eclipse/jetty/jetty-http/9.2.21.v20170120/jetty-http-9.2.21.v20170120.pom from central
Retrieving org/eclipse/jetty/jetty-util/9.2.21.v20170120/jetty-util-9.2.21.v20170120.pom from central
Retrieving org/eclipse/jetty/jetty-io/9.2.21.v20170120/jetty-io-9.2.21.v20170120.pom from central
Retrieving ring-server/ring-server/0.5.0/ring-server-0.5.0.jar from clojars
Retrieving watchtower/watchtower/0.1.1/watchtower-0.1.1.jar from clojars
Retrieving ring-refresh/ring-refresh/0.1.2/ring-refresh-0.1.2.jar from clojars
2019-06-19 09:04:36.286:INFO::main: Logging initialized @3875ms to org.eclipse.jetty.util.log.StdErrLog
2019-06-19 09:04:41.147:INFO:oejs.Server:main: jetty-9.4.12.v20180830; built: 2018-08-30T13:59:14.071Z; git: 27208684755d94a92186989f695db2d7b21ebc51; jvm 1.8.0_212-8u212-b01-1-b01
2019-06-19 09:04:41.421:INFO:oejs.AbstractConnector:main: Started [email protected]{HTTP/1.1,[http/1.1]}{0.0.0.0:3000}
2019-06-19 09:04:41.422:INFO:oejs.Server:main: Started @9011ms
Started server on port 3000
Exception in thread "main" Syntax error compiling at (/tmp/form-init1189940454145333408.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.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:204)
        at java.awt.Window.<init>(Window.java:536)
        at java.awt.Frame.<init>(Frame.java:420)
        at java.awt.Frame.<init>(Frame.java:385)
        at javax.swing.JFrame.<init>(JFrame.java:189)
        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__4181.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$eval5562.invokeStatic(form-init1189940454145333408.clj:1)
        at user$eval5562.invoke(form-init1189940454145333408.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

Yes, use server-headless. The only difference is that server will attempt to open a browser for you, which doesn’t work in WSL. You’ll just have to open the browser manually.

1 Like