I'm a newbie to ring development, and I'm trying to uberjar up what little I've got developed so far so I can put it out on a demo server. But when I run lein1 uberjar, the process involves compiling the code, and when it compiles, for some reason it seems to automatically invoke the server, so the uberjar never completes.... everything just locks up while my server sits there listening on port 8080, from which I have to Ctrl-C to kill.
My code looks like this: (snippet)
(defonce server (ring.adapter.jetty/run-jetty #'app {:host "127.0.0.1" :port 8080 :join? false}))
(defn -main [& m] (let [mode (keyword (or (first m) :dev)) port (Integer. (get (System/getenv) "PORT" "8080"))] (server port {:mode mode })))
And the message I get on compilation is: Jamess-MacBook-Pro-Retina:choozy.git jr$ lein1 uberjar Copying 40 files to /Users/jr/opt/choozy.git/lib Compiling me.choozy.www.web.server 2012-08-19 23:06:42.543:INFO:oejs.Server:jetty-7.6.1.v20120215 2012-08-19 23:06:42.571:INFO:oejs.AbstractConnector:Started SelectChannelConnec...@127.0.0.1:8080
The run-jetty function does what the name suggests: it runs Jetty.
You're defining "server" with defonce, but then trying to use it as a
function. I'm also not sure why you have {:mode mode} in your code
snippet. What's that meant to do?
You want something more like:
(defn server [port]
(run-jetty #'app {:port port})
But you might want to look into Lein-Ring instead of starting the
server yourself via -main.
- James
On 20 August 2012 07:07, JR <james.rother...@gmail.com> wrote:
> I'm a newbie to ring development, and I'm trying to uberjar up what little I've got developed so far so I can put it out on a demo server. But when I run lein1 uberjar, the process involves compiling the code, and when it compiles, for some reason it seems to automatically invoke the server, so the uberjar never completes.... everything just locks up while my server sits there listening on port 8080, from which I have to Ctrl-C to kill.
> (defn -main
> [& m]
> (let [mode (keyword (or (first m) :dev))
> port (Integer. (get (System/getenv) "PORT" "8080"))]
> (server port {:mode mode
> })))
> And the message I get on compilation is:
> Jamess-MacBook-Pro-Retina:choozy.git jr$ lein1 uberjar
> Copying 40 files to /Users/jr/opt/choozy.git/lib
> Compiling me.choozy.www.web.server > 2012-08-19 23:06:42.543:INFO:oejs.Server:jetty-7.6.1.v20120215
> 2012-08-19 23:06:42.571:INFO:oejs.AbstractConnector:Started SelectChannelConnec...@127.0.0.1:8080
On Mon, Aug 20, 2012 at 2:07 PM, JR <james.rother...@gmail.com> wrote:
> Hi:
> I'm a newbie to ring development, and I'm trying to uberjar up what little
> I've got developed so far so I can put it out on a demo server. But when I
> run lein1 uberjar, the process involves compiling the code, and when it
> compiles, for some reason it seems to automatically invoke the server, so
> the uberjar never completes.... everything just locks up while my server
> sits there listening on port 8080, from which I have to Ctrl-C to kill.
> (defn -main
> [& m]
> (let [mode (keyword (or (first m) :dev))
> port (Integer. (get (System/getenv) "PORT" "8080"))]
> (server port {:mode mode
> })))
> And the message I get on compilation is:
> Jamess-MacBook-Pro-Retina:choozy.git jr$ lein1 uberjar
> Copying 40 files to /Users/jr/opt/choozy.git/lib
> Compiling me.choozy.www.web.server > 2012-08-19 23:06:42.543:INFO:oejs.Server:jetty-7.6.1.v20120215
> 2012-08-19 23:06:42.571:INFO:oejs.AbstractConnector:Started
> SelectChannelConnec...@127.0.0.1:8080
I guess I was surprised that "lein compile" was actually invoking the
top-level functions. When I finally wrapped my head around this, I
moved the run-jetty down below a top-level function in main -- if main
got called with no parms, then it did nothing; if it got called with a
parm, then it started jetty using that port. So now the uberjar works,
because it never invokes the main with a parm. Then everything gets
packaged up nicely. When I invoke from the command line, I pass in my
port and everything is kosher.
With your method, won't you run into the same problem? So if your main
method does a reset! on the atom, won't this get invoked on
compilation?
You see, the only problem is that I'm compiling & jar-ing, but
invoking the server interrupts the compilation/jar-ing, and starts
listening!!! Then I have to Ctrl-C to kill the listening Jetty so I
get my command line back. But then, I never got to the actual
uberjar-ing I needed.
> On Mon, Aug 20, 2012 at 2:07 PM, JR <james.rother...@gmail.com> wrote:
>> Hi:
>> I'm a newbie to ring development, and I'm trying to uberjar up what
>> little
>> I've got developed so far so I can put it out on a demo server. But when
>> I
>> run lein1 uberjar, the process involves compiling the code, and when it
>> compiles, for some reason it seems to automatically invoke the server, so
>> the uberjar never completes.... everything just locks up while my server
>> sits there listening on port 8080, from which I have to Ctrl-C to kill.
>> (defn -main
>> [& m]
>> (let [mode (keyword (or (first m) :dev))
>> port (Integer. (get (System/getenv) "PORT" "8080"))]
>> (server port {:mode mode
>> })))
>> And the message I get on compilation is:
>> Jamess-MacBook-Pro-Retina:choozy.git jr$ lein1 uberjar
>> Copying 40 files to /Users/jr/opt/choozy.git/lib
>> Compiling me.choozy.www.web.server >> 2012-08-19 23:06:42.543:INFO:oejs.Server:jetty-7.6.1.v20120215
>> 2012-08-19 23:06:42.571:INFO:oejs.AbstractConnector:Started
>> SelectChannelConnec...@127.0.0.1:8080
>> Any idea how to avoid this starting?
>> Thanks in Advance!!
-- Regards,
James Rothering
------------------------
(Msg) 206-888-1776
> I guess I was surprised that "lein compile" was actually invoking the
> top-level functions. When I finally wrapped my head around this, I
> moved the run-jetty down below a top-level function in main -- if main
> got called with no parms, then it did nothing; if it got called with a
> parm, then it started jetty using that port. So now the uberjar works,
> because it never invokes the main with a parm. Then everything gets
> packaged up nicely. When I invoke from the command line, I pass in my
> port and everything is kosher.
> With your method, won't you run into the same problem? So if your main
> method does a reset! on the atom, won't this get invoked on
> compilation?
> You see, the only problem is that I'm compiling & jar-ing, but
> invoking the server interrupts the compilation/jar-ing, and starts
> listening!!! Then I have to Ctrl-C to kill the listening Jetty so I
> get my command line back. But then, I never got to the actual
> uberjar-ing I needed.
> Regards,
> James
> On 8/20/12, Shen, Feng <shen...@gmail.com> wrote:
> > I also use lein uberjar to pack all deps in one file.
> > when file is loaded(when lein uberjar, all clj file should be load):
> > this form get executed:
> > On Mon, Aug 20, 2012 at 2:07 PM, JR <james.rother...@gmail.com> wrote:
> >> Hi:
> >> I'm a newbie to ring development, and I'm trying to uberjar up what
> >> little
> >> I've got developed so far so I can put it out on a demo server. But when
> >> I
> >> run lein1 uberjar, the process involves compiling the code, and when it
> >> compiles, for some reason it seems to automatically invoke the server,
> so
> >> the uberjar never completes.... everything just locks up while my server
> >> sits there listening on port 8080, from which I have to Ctrl-C to kill.
Compiling doesn't invoke top level functions. Your code itself invokes run-jetty at the top level on this line: (defonce server (ring.adapter.jetty/run-jetty #'app {:host "127.0.0.1" :port 8080 :join? false}))
That is invoking run-jetty and assigning it result to the server var. If instead run-jetty was called in the body of a function, it wouldn't get invoked when the namespace was compiled.
On Tuesday, August 21, 2012 4:54:08 PM UTC-5, JR wrote:
> I guess I was surprised that "lein compile" was actually invoking the > top-level functions. When I finally wrapped my head around this, I > moved the run-jetty down below a top-level function in main -- if main > got called with no parms, then it did nothing; if it got called with a > parm, then it started jetty using that port. So now the uberjar works, > because it never invokes the main with a parm. Then everything gets > packaged up nicely. When I invoke from the command line, I pass in my > port and everything is kosher.
> With your method, won't you run into the same problem? So if your main > method does a reset! on the atom, won't this get invoked on > compilation?
> You see, the only problem is that I'm compiling & jar-ing, but > invoking the server interrupts the compilation/jar-ing, and starts > listening!!! Then I have to Ctrl-C to kill the listening Jetty so I > get my command line back. But then, I never got to the actual > uberjar-ing I needed.
> Regards,
> James
> On 8/20/12, Shen, Feng <she...@gmail.com <javascript:>> wrote: > > I also use lein uberjar to pack all deps in one file.
> > when file is loaded(when lein uberjar, all clj file should be load): > > this form get executed:
> > On Mon, Aug 20, 2012 at 2:07 PM, JR <james.r...@gmail.com <javascript:>> > wrote:
> >> Hi:
> >> I'm a newbie to ring development, and I'm trying to uberjar up what > >> little > >> I've got developed so far so I can put it out on a demo server. But > when > >> I > >> run lein1 uberjar, the process involves compiling the code, and when it > >> compiles, for some reason it seems to automatically invoke the server, > so > >> the uberjar never completes.... everything just locks up while my > server > >> sits there listening on port 8080, from which I have to Ctrl-C to kill.
> I guess I was surprised that "lein compile" was actually invoking the
> top-level functions. When I finally wrapped my head around this, I
> moved the run-jetty down below a top-level function in main -- if main
> got called with no parms, then it did nothing; if it got called with a
> parm, then it started jetty using that port. So now the uberjar works,
> because it never invokes the main with a parm. Then everything gets
> packaged up nicely. When I invoke from the command line, I pass in my
> port and everything is kosher.
> With your method, won't you run into the same problem? So if your main
> method does a reset! on the atom, won't this get invoked on
> compilation?
> You see, the only problem is that I'm compiling & jar-ing, but
> invoking the server interrupts the compilation/jar-ing, and starts
> listening!!! Then I have to Ctrl-C to kill the listening Jetty so I
> get my command line back. But then, I never got to the actual
> uberjar-ing I needed.
> Regards,
> James
> On 8/20/12, Shen, Feng <shen...@gmail.com> wrote:
>> I also use lein uberjar to pack all deps in one file.
>> when file is loaded(when lein uberjar, all clj file should be load):
>> this form get executed:
>> On Mon, Aug 20, 2012 at 2:07 PM, JR <james.rother...@gmail.com> wrote:
>>> Hi:
>>> I'm a newbie to ring development, and I'm trying to uberjar up what
>>> little
>>> I've got developed so far so I can put it out on a demo server. But when
>>> I
>>> run lein1 uberjar, the process involves compiling the code, and when it
>>> compiles, for some reason it seems to automatically invoke the server, so
>>> the uberjar never completes.... everything just locks up while my server
>>> sits there listening on port 8080, from which I have to Ctrl-C to kill.
>>> (defn -main
>>> [& m]
>>> (let [mode (keyword (or (first m) :dev))
>>> port (Integer. (get (System/getenv) "PORT" "8080"))]
>>> (server port {:mode mode
>>> })))
>>> And the message I get on compilation is:
>>> Jamess-MacBook-Pro-Retina:choozy.git jr$ lein1 uberjar
>>> Copying 40 files to /Users/jr/opt/choozy.git/lib
>>> Compiling me.choozy.www.web.server >>> 2012-08-19 23:06:42.543:INFO:oejs.Server:jetty-7.6.1.v20120215
>>> 2012-08-19 23:06:42.571:INFO:oejs.AbstractConnector:Started
>>> SelectChannelConnec...@127.0.0.1:8080
>>> Any idea how to avoid this starting?
>>> Thanks in Advance!!
> --
> Regards,
> James Rothering
> ------------------------
> (Msg) 206-888-1776