官术网_书友最值得收藏!

Creating a new project

Leiningen can help us create a new project using templates, there is a wide variety of templates available and you can build and distribute your own in Maven.

Some of the most common types of templates are:

  • Creating a jar library (the default template)
  • Creating a command-line app
  • Creating a Clojure web app

Let's create a new Clojure command-line app and run it:

lein new app getting-started
cd getting-started
lein run
# Hello, world!

Project structure

Leiningen is similar to other Java development tools; it uses a similar convention and allows for heavy customizations in the project.clj file.

If you are familiar with Maven or Gradle, you can think of it as pom.xml or build.gradle respectively.

The following screenshot is the project structure:

As you can see in the preceding screenshot, there are four main folders:

  • resources: It holds everything that should be in the class path, such as files, images, configuration files, properties files, and other resources needed at runtime.
  • src: Your Clojure source files; they are ordered in a very similar fashion to the classpath.
  • dev-resources: Everything that should be in the classpath in development (when you are running Leiningen). You can override your "production" files here and add files that are needed for tests to run.
  • test: Your tests; this code doesn't get packaged but it is run every time you execute the Leiningen test.

Creating a standalone app

Once your project is created, you can build and run a Java standalone command-line app quite easily, let's try it now:

lein uberjar
java -jar target/uberjar/getting-started-0.1.0-SNAPSHOT-standalone.jar
# Hello, World!

As you can see, it is quite easy to create a standalone app and it is very similar to using Maven or Gradle.

主站蜘蛛池模板: 五华县| 江达县| 万全县| 南涧| 海原县| 绵竹市| 大连市| 永顺县| 沈阳市| 济源市| 新密市| 太仓市| 新津县| 汾阳市| 鹤壁市| 中卫市| 苍山县| 晋宁县| 商城县| 蓝山县| 林周县| 阿合奇县| 三河市| 巴林右旗| 神农架林区| 呼伦贝尔市| 拉萨市| 哈密市| 平利县| 赫章县| 宜州市| 英吉沙县| 仁布县| 南木林县| 韩城市| 江门市| 济宁市| 溧水县| 永康市| 大化| 庆阳市|