Intellij Idea jar与外部库的问题

kqlmhetl  于 5个月前  发布在  其他
关注(0)|答案(1)|浏览(58)

我为我的程序创建了一个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

字符串
我在网上读了很多可能的解决方案,但任何一个都可以帮助我。

tkclm6bt

tkclm6bt1#

你需要创建一个jar,里面有库,或者在类路径中包含那些库。为了让那些库在jar中,你可以使用shade插件。将其添加到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></plugin>

字符串

相关问题