13
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Gradleで実行可能なjarファイルを作成する

Last updated at Posted at 2018-02-18

前提条件

  • intelliJ
  • java8

手順

intelliJで、Gradleプロジェクトを作成する

スクリーンショット 2018-02-18 18.59.58.png

簡単なJavaプログラムを作成して、Gradleの設定ファイルを編集する

src/main/java/HelloWorld.java
public class HelloWorld {
    public static void main(String... args) {
        System.out.println("Hello World");
    }
}

build.gradle(一部抜粋)

build.gradle
group 'helloworld'
version '1.0-SNAPSHOT'

apply plugin: 'java'

sourceCompatibility = 1.8

// (中略)

jar {
    manifest {
        attributes 'Main-Class': 'HelloWorld'
    }
}

実際にjarファイルを作成する

以下のgradleコマンドを実行すれば、プロジェクトのbuildディレクトリ配下にjarファイルが作成される

$ gradle build
Starting a Gradle Daemon (subsequent builds will be faster)
:compileJava
:processResources UP-TO-DATE
:classes
:jar
:assemble
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build

BUILD SUCCESSFUL

Total time: 7.82 secs
スクリーンショット 2018-02-18 19.02.42.png
13
17
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?