在maven中创建可执行jar文件,清单中缺少主类

时间:2019-02-11 13:59:48

标签: java swing manifest.mf

这是我的pom.xml,我该如何制作一个可执行jar,我在google中读到它需要在manifest.mf中有主类。我尝试使用addind插件,但一无所获     enter image description here      -

 <?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.mycompany</groupId>
               <artifactId>Sims_for_Import</artifactId>
               <version>1.0-SNAPSHOT</version>
               <packaging>jar</packaging>
               <properties>
                   <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
                   <maven.compiler.source>1.8</maven.compiler.source>
                   <maven.compiler.target>1.8</maven.compiler.target>
               </properties>
               <dependencies>
             <dependency>
             <groupId>com.oracle</groupId>
             <artifactId>ojdbc6</artifactId>
             <version>11.2.0.3</version>
               <!--<scope>system</scope>-->
               <!--<systemPath>${basedir}/ojdbc6-11.2.0.3.jar</systemPath>-->
           </dependency>
            <dependency>
                  <groupId>com.microsoft.sqlserver</groupId>
             <artifactId>sqljdbc42</artifactId>
             <version>4.2</version>
            </dependency>
               </dependencies>
               <name>Sims_for_Import</name>
           </project>

1 个答案:

答案 0 :(得分:1)

您应该使用maven-jar-plugin打包jar文件并提供一个主类:

<build>
    <plugins>
        <!-- ... other plugins ... -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.1.1</version>
            <configuration>
                <archive>
                    <manifest>
                        <!-- Your main class -->
                        <mainClass>sims_for_import.Main</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>

您可以在maven central repository上看到最新可用插件版本的列表。