• Stars
    star
    500
  • Rank 85,419 (Top 2 %)
  • Language
    Clojure
  • License
    Eclipse Public Li...
  • Created over 13 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Ring plugin for Leiningen

Lein-Ring

Lein-Ring is a Leiningen plugin that automates common Ring tasks.

It provides commands to start a development web server, and to turn a Ring handler into a standard war file.

Install

To use Lein-Ring, add it as a plugin to your project.clj file or your global profile:

:plugins [[lein-ring "0.12.6"]]

Then add a new :ring key to your project.clj file that contains a map of configuration options. At minimum there must be a :handler key that references your Ring handler:

:ring {:handler hello-world.core/handler}

When this is set, you can use Lein-Ring's commands.

General options

As well as the handler, you can specify several additional options via your project.clj file:

  • :init - A function to be called once before your handler starts. It should take no arguments. If you've compiled your Ring application into a war-file, this function will be called when your handler servlet is first initialized.

  • :destroy - A function called before your handler exits or is unloaded. It should take no arguments. If your Ring application has been compiled into a war-file, then this will be called when your handler servlet is destroyed.

  • :adapter - A map of options to be passed to the Ring adapter. This has no effect if you're deploying your application as a war-file.

  • :async? - If true, treat handler as an async handler. Default false.

Environment variables

Lein-Ring pays attention to several environment variables, including:

  • PORT - the port the web server uses for HTTP
  • SSLPORT - the port the web server uses for HTTPS

These will override any options specified in the project.clj file, but won't override any options specified at the command line.

Starting a web server

The following command will start a development web server, and opens a web browser to the root page:

lein ring server

If the LEIN_NO_DEV environment variable is not set, the server will monitor your source directory for file modifications, and any altered files will automatically be reloaded.

By default, this command attempts to find a free port, starting at 3000, but you can specify your own port as an argument:

lein ring server 4000

The server-headless command works like the server command, except that it doesn't open a web browser:

lein ring server-headless

lein ring server-headless 4000

Web server options

The following options affect the behavior of the web server started by lein ring server:

  • :port - The server port or port range

  • :stacktraces? - If true, display a stacktrace when an exception is thrown. Defaults to true for server or server-headless tasks. Ignored (always false) for generated artifacts.

  • :stacktrace-middleware - A symbol referencing the middleware to use for reporting errors. Defaults to ring.middleware.stacktrace/wrap-stacktrace.

  • :auto-reload? - If true, automatically reload modified source files. Defaults to true for server or server-headless tasks. Ignored (always false) for generated artifacts.

  • :reload-paths - A collection of directory paths that can trigger a reload. By default this takes all directories in the project classpath.

  • :auto-refresh? - If true, automatically refresh the browser when files are modified. Defaults to false. Ignored (always false) for generated artifacts.

  • :refresh-paths - A collection of directory paths that can trigger a refresh. Defaults to monitoring the src and resources directories.

  • :nrepl - A map of :start? and (optionally) :port and :host keys. If :start? is true, open up an nREPL server on the given port. :start? defaults to false, :port defaults to an arbitrary free port, and :host defaults to "localhost". NOTE: This option is only for development with the lein ring server task. Setting this option will not cause a generated uberjar/uberwar to run an nREPL server. If you would like to run an nREPL server in your production app, then see the clojure.tools.nrepl.server project.

Executable jar files

Lein-Ring can generate executable jar files for deployment purposes:

lein ring uberjar

This generates a jar file with all dependencies. You can then copy the file to your web server and execute it with:

java -jar <project>-<version>-standalone.jar

War files

Compiling

Lein-Ring can generate war files that can be loaded onto legacy Java web services such as Apache Tomcat:

lein ring war

A servlet class and web.xml file will be generated automatically, and your application packaged up in a war file.

Like the lein jar command, you can specify the filename being generated as an additional option:

lein ring war my-app.war

Also provided is a lein ring uberwar command, which packages up all the dependencies into the war:

lein ring uberwar

The following war-specific options are supported:

  • :war-exclusions - A list of regular expressions for excluding files from the target war. Defaults to excluding hidden files.

  • :servlet-class - The servlet class name.

  • :servlet-name - The name of the servlet (in web.xml). Defaults to the handler name.

  • :url-pattern - The url pattern of the servlet mapping (in web.xml). Defaults to "/*".

  • :servlet-path-info? - If true, a :path-info key is added to the request map. Defaults to true.

  • :listener-class - Class used for servlet init/destroy functions. Called listener because underneath it uses a ServletContextListener.

  • :web-xml - web.xml file to use in place of auto-generated version (relative to project root).

  • :servlet-version - The version of the servlet spec that we claim to conform to. Attributes corresponding to this version will be added to the web-app element of the web.xml. If not specified, defaults to 2.5.

  • :uberwar-name - The name of the file generated by lein ring uberwar.

  • :exploded - If true, will generate an exploded war directory instead of a war file. If not specified, defaults to false.

These keys should be placed under the :ring key in project.clj, and are optional values. If not supplied, default values will be used instead.

Resources

A war file can also include additional resource files, such as images or stylesheets. These should be placed in the directory specified by the Leiningen :resources-path key, which defaults to "resources". These resources will be placed on the classpath. To include multiple directories, use the Leiningen :resource-paths key, which should be a vector. The values in :resources-path and :resource-paths will be concatenated.

However, there is another sort of resource, one accessed through the ServletContext object. These resources are usually not on the classpath, and are instead placed in the root of the war file. If you happen to need this functionality, you can place your files in the directory specified by the :war-resources-path key (within the project map, rather than the map specified by :ring), which defaults to "war-resources". (As with normal resources, here you can use :war-resource-paths to include multiple directories.) It's recommended that you only use WAR resources for compatibility with legacy Java interfaces; under most circumstances, you should use the normal :resources-path instead.

License

Copyright © 2015 James Reeves, Michael Blume

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

More Repositories

1

compojure

A concise routing library for Ring/Clojure
Clojure
4,029
star
2

hiccup

Fast library for rendering HTML in Clojure
Clojure
2,571
star
3

integrant

Micro-framework for data-driven architecture
Clojure
1,197
star
4

cljfmt

A tool for formatting Clojure code
Clojure
1,081
star
5

environ

Library for managing environment variables in Clojure
Clojure
915
star
6

medley

A lightweight library of useful Clojure functions
Clojure
842
star
7

codox

Clojure documentation tool
Clojure
663
star
8

ragtime

Database-independent migration library
Clojure
603
star
9

hashp

A better "prn" for debugging
Clojure
433
star
10

eftest

Fast and pretty Clojure test runner
Clojure
420
star
11

clout

HTTP route-matching library for Clojure
Clojure
230
star
12

reagi

An FRP library for Clojure and ClojureScript
Clojure
230
star
13

ataraxy

A data-driven Ring routing and destructuring library
Clojure
207
star
14

crypto-password

Library for securely hashing passwords
Clojure
202
star
15

clj-aws-s3

S3 client library for Clojure
Clojure
198
star
16

reloaded.repl

REPL functions to support the reloaded workflow
Clojure
178
star
17

clojure-toolbox.com

Source to clojure-toolbox.com
CSS
176
star
18

clucy

Clojure interface to Lucene
Clojure
172
star
19

haslett

A lightweight WebSocket library for ClojureScript
Clojure
171
star
20

integrant-repl

Reloaded workflow functions for Integrant
Clojure
152
star
21

lein-beanstalk

Leiningen plugin for Amazon's Elastic Beanstalk service
Clojure
150
star
22

brutha

Simple ClojureScript interface to React
Clojure
139
star
23

ring-oauth2

OAuth 2.0 client middleware for Ring
Clojure
135
star
24

progrock

A functional Clojure progress bar for the command line
Clojure
133
star
25

lein-auto

A Leiningen plugin that executes tasks when files are modifed
Clojure
132
star
26

ns-tracker

Library to keep track of changes to Clojure source files
Clojure
112
star
27

meta-merge

A standalone implementation of Leiningen's meta-merge function
Clojure
101
star
28

ring-mock

Library to create mock ring requests for unit tests
Clojure
86
star
29

ring-anti-forgery

Ring middleware to prevent CSRF attacks
Clojure
76
star
30

crypto-random

Clojure library for generating cryptographically secure random bytes and strings
Clojure
71
star
31

crouton

HTML parsing library for Clojure
Clojure
66
star
32

comb

Clojure templating library
Clojure
66
star
33

ittyon

Library to manage distributed state for games
Clojure
58
star
34

compojure-example

An example Compojure project
Clojure
57
star
35

hiccup-bootstrap

Twitter's bootstrap in Hiccup
Clojure
56
star
36

lein-generate

Leiningen plugin for generating source file templates
Clojure
54
star
37

ring-server

Clojure
51
star
38

valip

Validations library for Clojure 1.2
Clojure
51
star
39

euclidean

Fast, immutable math for 3D geometries in Clojure
Clojure
51
star
40

impi

ClojureScript library for using Pixi.js through immutable data
Clojure
50
star
41

rotary

DynamoDB API for Clojure
Clojure
47
star
42

flupot

ClojureScript functions for creating React elements
Clojure
45
star
43

re-rand

Clojure library to generate random strings from regular expressions
Clojure
43
star
44

ring-webjars

Ring middleware to serve assets from WebJars
Clojure
35
star
45

abrade

Clojure library for web scraping
Clojure
32
star
46

ring-jetty-component

A component for the standard Ring Jetty adapter
Clojure
32
star
47

intentions

Multimethods that combine rather than override inherited behavior
Clojure
31
star
48

tcp-server

Clojure TCP server library
Clojure
31
star
49

ring-refresh

A Clojure middleware library for Ring that automatically triggers a browser refresh
Clojure
30
star
50

compojure-template

Compojure project template for Leiningen
Clojure
27
star
51

suspendable

A Clojure library to add suspend and resume methods to Component
Clojure
27
star
52

ring-serve

Ring development web server
Clojure
25
star
53

decorate

Clojure macros for decorating functions
Clojure
24
star
54

fact

Unit testing library for Clojure (no longer in active dev)
Clojure
23
star
55

crypto-equality

A small Clojure library for securely comparing strings or byte arrays
Clojure
23
star
56

resauce

Clojure library for handling JVM resources
Clojure
23
star
57

dotfiles

My configuration files
Emacs Lisp
21
star
58

inquest

A library for non-invasive monitoring in Clojure
Clojure
20
star
59

evaljs

Evaluate Javascript code and libraries in Clojure
Clojure
20
star
60

fish-git

Git completions and functions for the Fish Shell
18
star
61

dependency

A data structure for representing dependency graphs in Clojure
Clojure
17
star
62

snowball-stemmer

Snowball Stemmer for Clojure
Java
17
star
63

hop

An experimental declarative build tool for Clojure
Clojure
16
star
64

build

Clojure
15
star
65

coercer

Library to convert Clojure data into different types
Clojure
14
star
66

whorl

Generate unique fingerprints for Clojure data structures
Clojure
14
star
67

flupot-pixi

A ClojureScript wrapper around react-pixi
Clojure
13
star
68

clojure-over-ajax

Ajax Clojure REPL based on why's Try Ruby
JavaScript
13
star
69

websocket-example

Small example Ring/Aleph project for demonstrating websockets
Clojure
12
star
70

ring-json-response

Ring responses in JSON
Clojure
11
star
71

duct-hikaricp-component

Clojure component for managing a HikariCP connection pool
Clojure
10
star
72

crumpets

Clojure library for dealing with color
Clojure
9
star
73

clojure-dbm

Clojure interface to key-value databases
Clojure
9
star
74

hanami

A Clojure utility library for Heroku web applications
Clojure
9
star
75

strowger

A ClojureScript library for managing DOM events
Clojure
9
star
76

crypto-keystore

Clojure library for dealing with Java keystores
Clojure
8
star
77

substream

Stream subclassing in Clojure
Clojure
7
star
78

clj-daemon

Clojure daemon to avoid JVM startup time
Clojure
7
star
79

ring-reload-modified

Ring middleware that automatically reloads modifed source files
Clojure
7
star
80

duct-ragtime-component

Clojure component for managing migrations with Ragtime
Clojure
5
star
81

ring-honeybadger

Ring middleware for sending errors to HoneyBadger
Clojure
4
star
82

imprimatur

Data visualization library for ClojureScript and React
Clojure
4
star
83

hassium

Another Clojure MongoDB library
Clojure
4
star
84

contributing

Contributor's Guide
4
star
85

lein-template

Clojure
4
star
86

delegance

A Clojure library for remote evaluation
Clojure
3
star
87

po

A command-line tool for organizing project-specific scripts
Go
3
star
88

lein-version-script

A Leiningen plugin to set the project version from a shell script
Clojure
3
star
89

capra

An extensible package manager for Clojure
Clojure
3
star
90

eclair

Clojure
3
star
91

wrepl

Web-based Clojure REPL
Clojure
2
star
92

pocketses

Personal Wiki template that uses Gollum
CSS
2
star
93

clj-less

LESS interpreter for Clojure (http://lesscss.org)
Clojure
2
star
94

dewdrop

Web UI framework
2
star
95

ubitcoin

Bitcoin GUI for Ubuntu
Python
2
star
96

clojure-sandbox

Miscellaneous Clojure libraries that needed a home
Clojure
2
star
97

capra-server

RESTful package server
Clojure
1
star
98

delegance-aws

Library to integrate Delegance with Amazon Web Services
Clojure
1
star
99

weavejester.github.com

JavaScript
1
star
100

dojo-poetry

Code for Clojure Dojo 2012-08-28
Clojure
1
star