如何修复maven打包的jar报告'错误:无法找到或加载主类。\ FormulaTelemetryApp-1.0-SNAPSHOT.jar'

问题描述 投票:0回答:1

我正在尝试使用Maven打包我的JavaFX应用程序,使用exec运行它:java没有问题并且运行maven - package不会产生错误。但是当我想执行runnable jar时,它返回错误'Error:找不到或加载主类。\ FormulaTelemetryApp-1.0-SNAPSHOT.jar',其中第二部分是我想要执行的jar。

在我的下面包括我的POM,我已经去寻找解决方案,这是我偶然发现maven-jar-plugin的地方,但包括那些并没有解决问题。我也尝试过清理项目并再次编译/打包,但这也没有改变任何东西。

正如您可能注意到的,我对Maven相当新(尝试自学)因此POM中可能会有一些奇怪的东西。

<?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.formulaElectric</groupId>
    <artifactId>FormulaTelemetryApp</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>FormulaTelemetryApp</name>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>11</release>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.6.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>java</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <mainClass>org.feb.telemetry.application.TelemetryApplication</mainClass>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.1.1</version>
                <configuration>
                    <archive>
                        <index>true</index>
                        <manifest>
                            <mainClass>org.feb.telemetry.application.TelemetryApplication</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <distributionManagement>
        <!-- use the following if you're not using a snapshot version. -->
        <repository>
            <id>localSnap</id>
            <name>RepositoryProxyRel</name>
            <url>http://127.0.0.1:8080/nexus/content/repositories/releases/</url>
        </repository>
        <!-- use the following if you ARE using a snapshot version. -->
        <snapshotRepository>
            <id>MylocalSnap</id>
            <name>RepositoryProxySnap</name>
            <url>http://127.0.0.1:8080/nexus/content/repositories/snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>11</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>11</version>
        </dependency>
        <dependency>
            <groupId>org.controlsfx</groupId>
            <artifactId>controlsfx</artifactId>
            <version>9.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-collections4</artifactId>
            <version>4.1</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.23</version>
        </dependency>
        <dependency>
            <groupId>com.fazecast</groupId>
            <artifactId>jSerialComm</artifactId>
            <version>1.3.11</version>
        </dependency>
        <dependency>
            <groupId>eu.hansolo</groupId>
            <artifactId>tilesfx</artifactId>
            <version>1.4.7</version>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>23.0-rc1</version>
        </dependency>
        <dependency>
            <groupId>com.sun.mail</groupId>
            <artifactId>javax.mail</artifactId>
            <version>1.6.2</version>
        </dependency>
        <dependency>
            <groupId>org.xerial</groupId>
            <artifactId>sqlite-jdbc</artifactId>
            <version>3.21.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.1</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>com.jcraft</groupId>
            <artifactId>jsch</artifactId>
            <version>0.1.55</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.2</version>
        </dependency>
        <dependency>
            <groupId>org.jetbrains</groupId>
            <artifactId>annotations</artifactId>
            <version>RELEASE</version>
            <scope>compile</scope>
        </dependency>

    </dependencies>

</project>
java maven javafx executable-jar maven-package
1个回答
0
投票

正如评论中所述,问题是双重的:一方面需要一个胖罐,而maven-shade-plugin则用于此。除此之外,需要一个启动器类(非应用程序扩展类)作为主类,正如question的答案中所述。

© www.soinside.com 2019 - 2024. All rights reserved.