【问题标题】:Create executable jar file in maven,missing main-class in manifest在maven中创建可执行jar文件,清单中缺少主类
【发布时间】:2019-02-11 13:59:48
【问题描述】:

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

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

【问题讨论】:

    标签: java swing manifest.mf


    【解决方案1】:

    您应该使用maven-jar-plugin 来打包您的jarfile 并提供一个主类:

    <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 上查看最新可用插件版本的列表。

    【讨论】:

      猜你喜欢
      • 2018-07-24
      • 2020-04-10
      • 2019-10-06
      • 1970-01-01
      • 2019-05-04
      • 2019-08-09
      • 2020-05-20
      • 2017-11-14
      • 2019-09-20
      相关资源
      最近更新 更多