Fork me on GitHub
#ring
<
2017-01-10
>
sova-soars-the-sora19:01:44

Hi. I am working on a cljs project. Figwheel runs it Awesomely. I want to make sure I can deploy this to my remote server when i'm all done, so I'm making sure lein ring uberjar works as expected

sova-soars-the-sora19:01:20

However, when I make an uberjar and try java -jar target/nf-0.0.2-standalone.jar ... the server does start but accessing the root url gives the following error:

sova-soars-the-sora19:01:24

"Problem accessing /. Reason: java.lang.NullPointerException"

sova-soars-the-sora19:01:56

So I get a 500 response and I don't know why.

sova-soars-the-sora19:01:16

My :figwheel line in my >project.clj

sova-soars-the-sora19:01:23

looks like :figwheel {:ring-handler nf.core/handler}

sova-soars-the-sora19:01:32

and my :ring line looks very similar...

sova-soars-the-sora19:01:38

:ring {:handler nf.core/handler :port 8440}

sova-soars-the-sora19:01:59

but the lein ring uberjar ... no dice ... lil help?

weavejester19:01:26

sova: How are you compiling your production cljs code? cljsbuild?

sova-soars-the-sora19:01:10

@weavejester I totally forgot about that step.

sova-soars-the-sora19:01:36

I just tried lein cljsbuild once but I still get the same error after packing up the uberjar...

weavejester19:01:20

You need to have a :cljsbuild key in your project file, and you need to build your JS as part of your compilation.

weavejester19:01:27

Let me dig out an example

weavejester19:01:26

Ah, give me a few minutes.

sova-soars-the-sora19:01:31

Okay no stress. Thanks a lot

sova-soars-the-sora19:01:39

I have a pretty good idea of what that looks like..

sova-soars-the-sora19:01:22

it's great because everything loads perfectly with lein figwheel but i'm losing something in translation..

sova-soars-the-sora19:01:00

thanks for your good juju haha

sova-soars-the-sora19:01:18

(by the way, thanks a lot for ring and all the awesome work you do, i'm a big fan.)

weavejester19:01:24

Sorry for the delay. Do you have keys like:

weavejester19:01:31

:resource-paths ["resources" "target/cljsbuild"]
  :prep-tasks [["javac"] ["cljsbuild" "once"] [”compile"]]

sova-soars-the-sora20:01:13

Aum... I have a :resource-paths ["resources"] ... I shall add the prep-tasks one now

weavejester20:01:18

Because to make it work consistently, you need to ensure that the code is built in the prep-tasks before the jar, and that the cljs code you build is somewhere on the resource path

sova-soars-the-sora20:01:07

Gotcha. So those lines make sure the cljs gets compiled and added?

weavejester20:01:40

Yeah, as long as your compile target for cljsbuild is “target/cljsbuild"

weavejester20:01:51

Yours might be different.

sova-soars-the-sora20:01:56

It is different. :output-to "resources/public/js/nf_app.js" :output-dir "resources/public/js/out" ...

sova-soars-the-sora20:01:41

would it then be :resource-paths ["resources" "resources/public/js"] ?

weavejester20:01:53

Oh, there’s no need because “resources” covers “resources/public/js"

weavejester20:01:28

So you’re fine. You just need to either manually call cljsbuild once before every build, or add it to a prep-task

sova-soars-the-sora20:01:28

I love working with Clojure and Cljs because typically when you get something working you never have to touch it again haha

weavejester20:01:51

I also tend to have a line like:

weavejester20:01:18

:profiles {:repl {:prep-tasks ^:replace [["javac"] [”compile”]]}}

weavejester20:01:35

Because that ensures that starting the REPL doesn’t recompile my cljs.

sova-soars-the-sora20:01:41

Interesting! So that makes sure that when you run lein repl it doesn't do the cljs prep-task... that's good to have & know

sova-soars-the-sora20:01:58

man there are so many possibilities for project.clj ... is crazey

weavejester20:01:40

Yep. Because I have Figwheel to do that, I only want to have the cljbuild happen during lein uberjar or lein run.

sova-soars-the-sora20:01:41

Supersweet. Thanks very much for your help dear sir.