luminus

bastilla 2021-05-30T10:49:10.005100Z

Oops..., I wasn't even capable of creating a new luminus project. (Luminus is in full strike mode on my PC, it seems. See paragraph A for details. My actual issue is paragraph B.) A) Even project creation fails now with Luminus templates. I tried all of these:

> lein new luminus luminuswar +re-frame +shadow-cljs +war
> lein new luminus luminuswar +re-frame +war
> lein new luminus luminuswar +war
In case of adding +shadow-cljs I also did:
> lein shadow compile app
All of them resulted in successfull project creation, means I could start the server:
> lein run
...
2021-05-30 11:11:47,796 [main] INFO  luminus.http-server - server started on port 3000
...
BUT here is the issue now. ALL these created projects are mis-configured, it seems:
&gt; wget <http://localhost:3000/>
--2021-05-30 11:01:41--  <http://localhost:3000/>
Resolving localhost (localhost)... 127.0.0.1
Connecting to localhost (localhost)|127.0.0.1|:3000... connected.
HTTP request sent, awaiting response... 404 Not Found
2021-05-30 11:01:41 ERROR 404: Not Found.
Same result with Firefox, too, of course. Here comes the funny part. This WORKS and gets me a running web site:
&gt; lein new luminus veryplainluminus
So I suspect the culprit is +war Some version numbers:
&gt; lein -version
Leiningen 2.9.4 on Java 11.0.11 OpenJDK 64-Bit Server VM
&gt; uname -a
Linux 4.4.0-197-generic #229+8.0trisquel3 SMP Tue Dec 1 13:00:01 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
B) My main issue: Luminus WAR files neither run under Tomcat nor Jetty: Luckily I created my server stuff months ago with +war, and it ran successfully in dev mode. I actually really didn't need it since I only deliver Clojurescript code to my customers. But now they urge me to also develop some Java stuff for their servers and Luminus just denies me building applicable WAR files. Some conf details: project.clj
:plugins [[lein-shadow "0.2.0"]
		  [lein-sassc "0.10.4"]
		  [lein-auto "0.1.2"]
		  [lein-uberwar "0.2.1"]]
:uberwar
  {:handler sfprj.handler/app
   :init sfprj.handler/init
   :destroy sfprj.handler/destroy
   :name "sfprj.war"}
When creating the uberwar the build process is doing everything 3 times over. (This is new and wasn't the case when I first tried it months ago.) This is why it's quite a lengthy output. (Sorry to bother you with this log bloat, but this shows I'm not making it up.)
&gt; lein uberwar
lein-shadow - running: npm --version
lein-shadow - NPM version 6.14.12
lein-shadow - running: npm install --save-dev --save-exact xmlhttprequest@1.8.0
lein-shadow - NPM install successful + xmlhttprequest@1.8.0updated 1 package and audited 9 packages in 1.901sfound 0 vulnerabilities
lein-shadow - running shadow-cljs...
[:app] Compiling ...
------ WARNING #1 -  -----------------------------------------------------------
 Resource: com/cognitect/transit.js:649:8
 variable module is undeclared
--------------------------------------------------------------------------------
nil
[:app] Build completed. (224 files, 0 compiled, 0 warnings, 52.06s)
Compiling sfprj.bundle.create
Compiling sfprj.bundle.csv-to-map
Compiling sfprj.bundle.folder-to-sql
Compiling sfprj.bundle.prep
Compiling sfprj.common-file-helper
Compiling sfprj.env
Compiling sfprj.handler
Compiling sfprj.layout
Compiling sfprj.middleware
Compiling sfprj.middleware.exception
Compiling sfprj.middleware.formats
Compiling sfprj.nrepl
Compiling sfprj.preview.preview-manager
Compiling sfprj.rootmanage.create
Compiling sfprj.rootmanage.writer
Compiling sfprj.routes.home
Compiling sfprj.routes.services
Compiling sfprj.routes.services.graphql
Compiling sfprj.validation
Compile SASS/SCSS files.
sassc -t nested -I resources/scss resources/scss/screen.scss resources/public/css/screen.css

Compiling sfprj.bundle.create
Compiling sfprj.bundle.csv-to-map
Compiling sfprj.bundle.folder-to-map.app-db
Compiling sfprj.bundle.folder-to-map.folder-structure
Compiling sfprj.bundle.folder-to-map.helper
Compiling sfprj.bundle.folder-to-map.id-storage
Compiling sfprj.bundle.folder-to-map.lists
Compiling sfprj.bundle.folder-to-map.objects
Compiling sfprj.bundle.folder-to-map.read
Compiling sfprj.bundle.folder-to-map.sitemap
Compiling sfprj.bundle.folder-to-map.transform
Compiling sfprj.bundle.folder-to-map.type-defs
Compiling sfprj.bundle.folder-to-sql
Compiling sfprj.bundle.helper
Compiling sfprj.bundle.prep
Compiling sfprj.bundle.tmp-style
Compiling sfprj.common-file-helper
Compiling sfprj.common-helper
Compiling sfprj.common-string-helper
Compiling sfprj.common-struct-helper
Compiling sfprj.config
Compiling sfprj.env
Compiling sfprj.handler
Compiling sfprj.helper
Compiling sfprj.layout
Compiling sfprj.middleware
Compiling sfprj.middleware.exception
Compiling sfprj.middleware.formats
Compiling sfprj.nrepl
Compiling sfprj.preview.preview-manager
Compiling sfprj.rootmanage.create
Compiling sfprj.rootmanage.path-manager
Compiling sfprj.rootmanage.reader
Compiling sfprj.rootmanage.writer
Compiling sfprj.routes.home
Compiling sfprj.routes.services
Compiling sfprj.routes.services.graphql
Compiling sfprj.validation
Compile SASS/SCSS files.
sassc -t nested -I resources/scss resources/scss/screen.scss resources/public/css/screen.css

lein-shadow - running: npm --version
lein-shadow - NPM version 6.14.12
lein-shadow - running: npm install --save-dev --save-exact xmlhttprequest@1.8.0
lein-shadow - NPM install successful + xmlhttprequest@1.8.0updated 1 package and audited 9 packages in 0.688sfound 0 vulnerabilities
lein-shadow - running shadow-cljs...
[:app] Compiling ...
------ WARNING #1 -  -----------------------------------------------------------
 Resource: com/cognitect/transit.js:649:8
 variable module is undeclared
--------------------------------------------------------------------------------
nil
[:app] Build completed. (224 files, 0 compiled, 0 warnings, 48.61s)
Compile SASS/SCSS files.
sassc -t nested -I resources/scss resources/scss/screen.scss resources/public/css/screen.css

lein-shadow - running: npm --version
lein-shadow - NPM version 6.14.12
lein-shadow - running: npm install --save-dev --save-exact xmlhttprequest@1.8.0
lein-shadow - NPM install successful + xmlhttprequest@1.8.0updated 1 package and audited 9 packages in 0.695sfound 0 vulnerabilities
lein-shadow - running shadow-cljs...
[:app] Compiling ...
------ WARNING #1 -  -----------------------------------------------------------
 Resource: com/cognitect/transit.js:649:8
 variable module is undeclared
--------------------------------------------------------------------------------
nil
[:app] Build completed. (224 files, 0 compiled, 0 warnings, 46.37s)
Compile SASS/SCSS files.
sassc -t nested -I resources/scss resources/scss/screen.scss resources/public/css/screen.css

lein-shadow - running: npm --version
lein-shadow - NPM version 6.14.12
lein-shadow - running: npm install --save-dev --save-exact xmlhttprequest@1.8.0
lein-shadow - NPM install successful + xmlhttprequest@1.8.0updated 1 package and audited 9 packages in 0.715sfound 0 vulnerabilities
lein-shadow - running shadow-cljs...
[:app] Compiling ...
------ WARNING #1 -  -----------------------------------------------------------
 Resource: com/cognitect/transit.js:649:8
 variable module is undeclared
--------------------------------------------------------------------------------
nil
[:app] Build completed. (224 files, 0 compiled, 0 warnings, 46.81s)
Created /.../sfprj/impl/server/sfprj/target/uberjar/sfprj.war
So, the process (`lein uberwar`) it doing stuff 3 x 47 seconds, where it should end after 1 x 47 seconds. But at least in the end I get a WAR file. Deploying it to tomcat ...
&gt; cp target/uberjar/sjprj.war /home/.../bin/apache-tomcat-9.0.37/webapps
... and running it yields...
&gt; cd /home/.../bin/apache-tomcat-9.0.37
&gt; ./bin/startup.sh
...
Tomcat started.
&gt; wget <http://localhost:8080/sfprj>
HTTP Status 500 – Internal Server Error

Type Exception Report

Message Wrong number of args (1) passed to: sfprj.handler/app

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

clojure.lang.ArityException: Wrong number of args (1) passed to: sfprj.handler/app
	clojure.lang.AFn.throwArity(AFn.java:429)
	clojure.lang.AFn.invoke(AFn.java:32)
	clojure.lang.Var.invoke(Var.java:384)
	sfprj.listener$_contextInitialized$fn__11.invoke(listener.clj:1)
	ring.util.servlet$make_blocking_service_method$fn__125.invoke(servlet.clj:113)
	sfprj.servlet$_service.invokeStatic(servlet.clj:1)
	sfprj.servlet$_service.invoke(servlet.clj:1)
	sfprj.servlet.service(Unknown Source)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

Note The full stack trace of the root cause is available in the server logs.
Apache Tomcat/9.0.37
Note, the log files don't give any more details. And this is the situation with Jetty.
&gt; export JETTY_HOME=/home/.../bin/jetty-home-11.0.2
&gt; cd /home/.../bin/jetty-base
&gt; java -jar $JETTY_HOME/start.jar --add-module=server,http,deploy
&gt; cp /.../sfprj.war webapps/
&gt; java -jar $JETTY_HOME/start.jar
...
java.lang.NoClassDefFoundError: javax/servlet/ServletContextListener
...
Caused by: 
java.lang.ClassNotFoundException: javax.servlet.ServletContextListener
Here I experimented with supplying servlet classes within the project (sfprj) but to no avail. I guess, the situation with Jetty is too much a mess. Tomcat at least is having no issues with missing servlet classes and delivers an error message regarding the project itself (wrong arity in a function call). Phew, quite a novel. Sorry! But these are the bloody details. I want to be as constructive and level headed and Commander Data-like as possible. But if I'd be the project lead of a company, Luminus would get a "strike and out!". Alas devs of that project didn't respond back then and will most likely not respond now. Bummer, because actually I really like Luminus approach of micro management. But sadly I have to regard it as "not production ready". I really hope I created that mess myself and someone points it out as being a mere PEBCAK. @jtlocsei if you see where I went wrong, I'd really appreciate that.

tobias 2021-05-30T11:55:54.005400Z

OK I think I've solved part A. It's a problem with the routes. I'll put up a repo in a minute.

tobias 2021-05-30T12:13:09.005600Z

Actually, not a bug. So, when you deploy to Tomcat, each app (i.e. each .war file in the /tomcat/webapps/ directory) us available at a URL with the same name as the app. So, if your app is called luminuswar, then in dev you need to go to localhost:3000/luminuswar/ (trailing slash is necessary). So, if you wget that address it should work. You can also see this if you look at the routes in luminuswar/routes/home.clj you'll see that the top-level route is "/luminuswar" to reflect this.

tobias 2021-05-30T12:15:02.005800Z

Unfortunately it looks like this messes up the path of css during dev, so the home page isn't styled properly.

tobias 2021-05-30T12:29:03.006Z

OK, so now I tried building an uberjar and deploying to Tomcat. I get an error too 😞

tobias 2021-05-30T12:31:19.006200Z

Might be worth raising an issue on the https://github.com/luminus-framework/luminus-template/. I rarely see Yogthos (the creator of Luminus) in this slack but in the past he's been pretty quick to respond to issues on github.

tobias 2021-05-30T12:45:22.006400Z

In the meantime, you can use an old version of the template. When I last used Tomcat it was Luminus template version 3.25. You can create an app from that template with: lein new luminus luminuswar --template-version 3.25 -- +war

1🙏1🙌
tobias 2021-05-30T12:47:47.006600Z

I get the feeling that hosting in Tomcat / Jetty is less common these days than it used to be. I always just run a standalone jar. This has the benefit that you can REPL in to your production app, which I don't think you can do with Tomcat / Jetty. But if your client demands a war then I guess that's what you need to go with.

bastilla 2021-05-30T14:10:09.006800Z

Hey @jtlocsei It's just awesome that you checked those issues so fast! Concerning dev mode and "feature not a bug" you are right, that this indeed works: http://localhost:3000/luminuswar/ ...but is documented differently: https://luminusweb.com/docs/guestbook.html#running_the_application and once I browse to 'home' via menu I get to http://localhost:3000 which is 404. So, food for Yogthos to correct. Concering WAR and tomcat, I really hope --template-version 3.25 -- will save the day. I'll post feedback on this next week since I have to set up / create the whole project again. But this is the most promising approach I had in like an eternity on this issue. Sooo many thanks @jtlocsei bows head in deep respect I'll finish this thread the upcoming days (hopefully!)... PS: And you are right, tomcat is outdated technology, but I don't have a choice.

tobias 2021-05-30T23:21:05.007200Z

Good luck! In case you end up giving up on Luminus for WAR files and trying to build something from scratch, here's the most minimal example I've found: https://github.com/Igneous/hello-ring-war

tobias 2021-05-30T23:22:04.007500Z

It's from this thread (where my username is notsohasty). Looking back I realise that even 9 months ago the +war profile in Luminus was not working. https://www.reddit.com/r/Clojure/comments/ieyc04/running_ten_of_simple_clojure_web_applications_on/

tobias 2021-05-30T23:32:02.007800Z

OK, so another stumbling block to look out for: If you try to run lein uberwar on a project generated with Luminus template version 3.25 you might get an error compiling, depending on your version of Leiningen. I had to downgrade to an older version to get it to work. Version 8.25 worked fine. See attached for how to change the version of Leiningen (luckily it's pretty quick to do).

tobias 2021-05-30T23:35:48.008200Z

Sorry, typo, I meant version 2.8.3 of Leiningen worked fine.