Building executable FatJar file using Maven, the Swing GUI Toolkit and Intellij as development IDE

256 views Asked by At

I am relatively new in Java programming and try to set up a Swing-based GUI with some action buttons (including ActionListener and ActionPerformed sections) as a first project. So far, I managed to create some buttons and assign some functions to them. Applying the standard play button on the main.java, which is then supposed to be my "current file",

Intellij screenshot
the output is working perfectly well:
Swingbutton-panel
The functions are further defined using a spread sheet file.

My problem now is how to use the maven pom.xml file and the Intellij IDE properly in order to create a (fat) jar file, which by doupleclicking will give me the programmed interface shown above. I have tried many things and checked out a lot of websites and youtube tutorials. The most helpful was propably this one so far: https://jenkov.com/tutorials/maven/maven-build-fat-jar.html

Furthermore, I use the Maven "clean package" command trying to build the file. The only things I could acchieve in this respect was to build non-functional jar files or "slim" jars on minimal examples, which just print a "hello world" in the shell when using "java -jre test.jar" command.

Can anyone help? Please pay attention to the "special combination" of Maven, fat-jar-building, the Swing-package and Intellij. Thanks so much in advance, I am excited to take your comments!

<!--<?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>com.jenkov.myprojectname</groupId>
    <artifactId>my-project-name</artifactId>
    <version>1.1.0</version>
    <packaging>jar</packaging>

    <name>My Project Name</name>
    <!--
        <properties>
            <maven.compiler.source>19</maven.compiler.source>
            <maven.compiler.target>19</maven.compiler.target>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>
        -->
    <dependencies>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>5.2.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>5.2.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.19.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.19.0</version>
        </dependency>
        <dependency>
            <groupId>org.webjars.npm</groupId>
            <artifactId>rc</artifactId>
            <version>1.2.8</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.seaglasslookandfeel/seaglasslookandfeel -->
        <dependency>
            <groupId>com.seaglasslookandfeel</groupId>
            <artifactId>seaglasslookandfeel</artifactId>
            <version>0.2.1</version>
        </dependency>
        <dependency>
            <groupId>com.formdev</groupId>
            <artifactId>flatlaf</artifactId>
            <version>3.0</version>
        </dependency>
        <dependency>
            <groupId>com.formdev</groupId>
            <artifactId>flatlaf-intellij-themes</artifactId>
            <version>3.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-assembly-plugin -->
        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>3.5.0</version>
        </dependency>


    </dependencies>
    <!-- Thanks for using https://jar-download.com -->

    <!-- https://jenkov.com/tutorials/maven/maven-build-fat-jar.html -->
    <build>
        <finalName>my-project-name</finalName>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>Main</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.1.1</version>

                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>

                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

fig01

fig02

fig03

fig04

fig05

0

There are 0 answers