0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

IntelliJを使い、gradleでjarファイルを作成する方法。【備忘録】

Last updated at Posted at 2024-12-27

IntelliJで、GradleでJarファイルを作成する方法。
いつも忘れて混乱するから、備忘録。
ちなみに、ビルドシステムで、IntelliJを選ぶと、Jarファイルを作るのが大変。
最初から、GradleかMavenを選びましょう!

1
GradleとGroovyを選ぶ。(Kotlinを選ぶと、Build時に謎のエラーがでる。)
名称未設定10.png

2
サンプルコードは、下記。

Main.java
package org.example;

class Main{
    public static void main (String[] args) {
        System.out.println("Hello Naiveprince1227");
    }
}


build.gradleファイルの追加部分は下記。

build.gradle

//追加する
jar{
    manifest{
        attributes 'Main-Class' : 'org.example.Main'//クラス名を指定する
    }
}
//追加ここまで

全体は、こんな感じ。
image.png


ビルドする。
image.png


ビルド完了
image.png


jarファイルが作成される。
image.png


ターミナルで動作確認
こんな感じでターミナルで動きます。

test_user@test-mac naiveprince1227r2 % cd build
test_user@test-mac build % ls
classes         generated       libs            tmp
test_user@test-mac build % cd libs
test_user@test-mac libs % ls
naiveprince1227r2-1.0-SNAPSHOT.jar
test_user@test-mac libs % java -jar naiveprince1227r2-1.0-SNAPSHOT.jar
Hello Naiveprince1227
test_user@test-mac libs % 
0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?