我为我的程序创建了一个 jar,但无法启动它。
我用 IntelliJ 创建了它,当我从 IntelliJ 启动它时它可以工作,但是当我尝试从 jar 启动它时它不起作用。 我用 maven 制作了我的项目,我必须导入两个外部库:Selenium 和 Apache Poi,我尝试用该依赖项注释该行并且它有效,但我需要使用它们。
Windows PowerShell 给我的错误是:
Error: Could not find or load main class com.example.calcoloeffemeridi.Launcher
Caused by: java.lang.ClassNotFoundException: com.example.calcoloeffemeridi.Launcher
我在网上阅读了很多可能的解决方案,但任何一个都可以帮助我。
您需要创建一个包含库的 jar 包或将其包含在类路径中。 为了将它们放入罐子中,您可以使用阴影插件。 将其添加到 pom 中
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.1</version>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>app.Main</mainClass> <!-- Here you should put the main class of your application -->
</transformer>
</transformers>
<filters>
<filter> <!-- This filter is needed to avoid a bug in the shade plugin -->
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>