반응형

[Java 기초 #5] maven jar - no main manifest attribute

 

1. maven jar - no main manifest attribute

2. 개발환경

    2.1. 개발환경

    2.2. 라이브러리

3. 구현

    3.1. 프로젝트 구조

    3.2. 소스코드

4. 결과

 

 

1. maven jar 만들기 - no main manifest attribute

 

 

2. 개발환경

 

2.1. 개발환경

MacOS M1 - macOS Monterey 12.0.1

IntelliJ IDEA 2021.2 (Community Edition)

 

2.2. 라이브러리

JDK 1.8

 

 

3. 구현 

3.1. 프로젝트 구조

 

3.2. 소스코드

[pom.xml]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
 
    <groupId>io.home.test</groupId>
    <artifactId>test-maven-hello</artifactId>
    <version>1.0-SNAPSHOT</version>
 
    <properties>
        <build.jdk.source>8</build.jdk.source>
        <build.jdk.target>8</build.jdk.target>
    </properties>
 
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.1</version>
                <configuration>
                    <source>${build.jdk.source}</source>
                    <target>${build.jdk.target}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.2.2</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>io.home.test.Test</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
 
</project>

 

[Hello.java]

1
2
3
4
5
public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

 

[Test.java]

1
2
3
4
5
6
7
package io.home.test;
 
public class Test {
    public static void main(String[] args) {
        System.out.println("Hello Test World!");
    }
}

 

 

4. 결과

maven clean install

 

실행 결과

 

no main manifest attribute 문제는 build plugin 추가하여 해결

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.2.2</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>io.home.test.Test</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>

 

 

반응형

'JAVA 자바 > JAVA 기초' 카테고리의 다른 글

[Java 기초 #4] JAR Manifest file 기본  (0) 2021.05.19
[Java 기초 #3] Manifest file (일반)  (0) 2021.05.17
[Java 기초 #2] JAR 파일  (0) 2021.05.17