Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Compiling starts jetty server, so I can't complete Uberjar
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
JR  
View profile  
 More options Aug 20 2012, 2:07 am
From: JR <james.rother...@gmail.com>
Date: Sun, 19 Aug 2012 23:07:50 -0700 (PDT)
Local: Mon, Aug 20 2012 2:07 am
Subject: Compiling starts jetty server, so I can't complete Uberjar

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.

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

Any idea how to avoid this starting?

Thanks in Advance!!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Reeves  
View profile  
 More options Aug 20 2012, 4:20 am
From: James Reeves <jree...@weavejester.com>
Date: Mon, 20 Aug 2012 09:20:15 +0100
Local: Mon, Aug 20 2012 4:20 am
Subject: Re: Compiling starts jetty server, so I can't complete Uberjar
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:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Shen, Feng  
View profile   Translate to Translated (View Original)
 More options Aug 20 2012, 9:37 pm
From: "Shen, Feng" <shen...@gmail.com>
Date: Tue, 21 Aug 2012 09:37:25 +0800
Local: Mon, Aug 20 2012 9:37 pm
Subject: Re: Compiling starts jetty server, so I can't complete Uberjar

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:

(defonce server (ring.adapter.jetty/run-jetty
             #'app {:host "127.0.0.1" :port 8080 :join? false}))

which effectively start jetty server.

Here is a way to fix it:
(defonce server (atom nil))

in -main

(reset! server (ring.adapter.jetty/run-jetty #'app {:host "127.0.0.1"
:port 8080 :join? false})

Here is a working example for your reference:
https://github.com/shenfeng/rssminer/blob/master/src/rssminer/main.clj


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Rothering  
View profile   Translate to Translated (View Original)
 More options Aug 21 2012, 5:54 pm
From: James Rothering <james.rother...@gmail.com>
Date: Tue, 21 Aug 2012 14:54:08 -0700
Local: Tues, Aug 21 2012 5:54 pm
Subject: Re: Compiling starts jetty server, so I can't complete Uberjar
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:

--
Regards,

James Rothering
------------------------
(Msg) 206-888-1776


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Shen, Feng  
View profile   Translate to Translated (View Original)
 More options Aug 21 2012, 8:22 pm
From: "Shen, Feng" <shen...@gmail.com>
Date: Wed, 22 Aug 2012 08:22:02 +0800
Local: Tues, Aug 21 2012 8:22 pm
Subject: Re: Compiling starts jetty server, so I can't complete Uberjar

--I guess I was surprised that "lein compile" was actually invoking the
top-level functions

Actually, `lein compile` will 'evaluate' all forms.
(defonce server (ring.adapter.jetty/run-jetty
             #'app {:host "127.0.0.1" :port 8080 :join? false}))

when this get 'evaluated', function start. This is something like `compile
time` evaluate found in other language, like c++

Functions are evaluate to functions, not call them, so main evaluate to
main, it will not get called.

Clojure never interpret, all are compiled to JVM byte code,   `evaluate` is
quoted.

hoping it helps.

沈锋
美味书签 http://mei.fm

On Wed, Aug 22, 2012 at 5:54 AM, James Rothering
<james.rother...@gmail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Trent Ogren  
View profile   Translate to Translated (View Original)
 More options Aug 21 2012, 8:23 pm
From: Trent Ogren <m...@trentogren.com>
Date: Tue, 21 Aug 2012 17:23:29 -0700 (PDT)
Local: Tues, Aug 21 2012 8:23 pm
Subject: Re: Compiling starts jetty server, so I can't complete Uberjar

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.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Reeves  
View profile   Translate to Translated (View Original)
 More options Aug 22 2012, 4:17 am
From: James Reeves <jree...@weavejester.com>
Date: Wed, 22 Aug 2012 09:17:36 +0100
Local: Wed, Aug 22 2012 4:17 am
Subject: Re: Compiling starts jetty server, so I can't complete Uberjar
The -main function is not invoked during compilation. The problem with
your code is that you started the server *outside* the -main function.

- James

On 21 August 2012 22:54, James Rothering <james.rother...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »