Intellij Idea jar与外部库的问题

kqlmhetl  于 2024-01-05  发布在  其他
关注(0)|答案(1)|浏览(125)

我为我的程序创建了一个jar,但我无法启动它。
我用IntelliJ创建了它,当我从IntelliJ启动它时,它可以工作,但是当我试图从jar启动它时,它不工作。我用maven做了我的项目,我不得不导入两个外部库:Selenium和Apache Poi,我试图用依赖项注解该行,它可以工作,但是我需要使用它们。
Windows PowerShell给我的错误是:

  1. Error: Could not find or load main class com.example.calcoloeffemeridi.Launcher
  2. Caused by: java.lang.ClassNotFoundException: com.example.calcoloeffemeridi.Launcher

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

tkclm6bt

tkclm6bt1#

你需要创建一个jar,里面有库,或者在类路径中包含那些库。为了让那些库在jar中,你可以使用shade插件。将其添加到pom

  1. <plugin>
  2. <groupId>org.apache.maven.plugins</groupId>
  3. <artifactId>maven-shade-plugin</artifactId>
  4. <version>3.4.1</version>
  5. <configuration>
  6. <transformers>
  7. <transformer
  8. implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
  9. <mainClass>app.Main</mainClass> <!-- Here you should put the main class of your application -->
  10. </transformer>
  11. </transformers>
  12. <filters>
  13. <filter> <!-- This filter is needed to avoid a bug in the shade plugin -->
  14. <artifact>*:*</artifact>
  15. <excludes>
  16. <exclude>META-INF/*.SF</exclude>
  17. <exclude>META-INF/*.DSA</exclude>
  18. <exclude>META-INF/*.RSA</exclude>
  19. </excludes>
  20. </filter>
  21. </filters>
  22. </configuration>
  23. <executions>
  24. <execution>
  25. <phase>package</phase>
  26. <goals>
  27. <goal>shade</goal>
  28. </goals>
  29. </execution>
  30. </executions></plugin>

字符串

展开查看全部

相关问题