简体   繁体   English

Jar 文件引用 Maven jar 文件不能始终如一地工作

[英]Jar file referencing Maven jar file doesn't work consistently

I have a Swing application that uses classes from Maven artifact math.geom2d:javaGeom:0.11.1 .我有一个 Swing 应用程序,它使用 Maven 工件math.geom2d:javaGeom:0.11.1中的类。 To create a jar file in A GitHub Release I use a modified "fatJar" build.gradle task, so the geom2d classes are included in the jar file. To create a jar file in A GitHub Release I use a modified "fatJar" build.gradle task, so the geom2d classes are included in the jar file. For the jar file for my application on Maven, I don't include the geom2d classes, so these classes don't show up in that jar file, but they are referenced as dependencies.对于我在 Maven 上的应用程序的 jar 文件,我不包括 geom2d 类,因此这些类不会出现在 jar 文件中,但它们被引用为依赖项

What is odd is that on my machine this (smaller) jar file works fine consistently, so I thought everything was OK, even if strange.奇怪的是,在我的机器上,这个(较小的)jar 文件始终可以正常工作,所以我认为一切都很好,即使很奇怪。 I decided to try it on my wife's machine and it crashes with a NoClassDefFoundError.我决定在我妻子的机器上试一试,结果它因 NoClassDefFoundError 而崩溃。 I thought maybe it was because she didn't have Maven installed.., tried installing it, but no difference!我想可能是因为她没有安装 Maven..,尝试安装它,但没有区别! Help would be appreciated!帮助将不胜感激!

Here is the pom.xml on Maven for my app:这是我的应用程序的 Maven 上的 pom.xml :

<project 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.jpaulmorrison</groupId>
<artifactId>drawfbp</artifactId>
<version>2.18.4</version>
<name>DrawFBP</name>
<description>Diagramming Tool for Flow-Based Programming</description>
<url>https://github.com/jpaulm/drawfbp</url>
<licenses>
<license>
<name>GNU Lesser General Public License, Version 3.0</name>
<url>https://www.gnu.org/licenses/lgpl-3.0.txt</url>
</license>
</licenses>
<developers>
<developer>
<id>jpaulmorr</id>
<name>
John Paul Rodker Morrison (Software architect/developer)
</name>
<email>jpaulmorr@gmail.com</email>
</developer>
<developer>
<id>bobcorrick</id>
<name>Bob Corrick (Software architect/developer)</name>
<email>bobcorrick@outlook.com</email>
</developer>
</developers>
<scm>
<connection>scm:git:https://github.com/jpaulm.git</connection>
<developerConnection>scm:git:https://github.com/jpaulm.git</developerConnection>
<url>https://github.com/jpaulm.git</url>
</scm>
<dependencies>
<dependency>
<groupId>math.geom2d</groupId>
<artifactId>javaGeom</artifactId>
<version>0.11.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

Thanks @samvel1024: I now have a better handle on what is going on:谢谢@samvel1024:我现在可以更好地处理正在发生的事情:

  • the jar file without the geom2d classes could run because I had geom2d in my classpath - it doesn't any more!没有 geom2d 类的 jar 文件可以运行,因为我的类路径中有 geom2d - 它不再存在了!

  • I create a fatJar using a task in build.gradle, but uploadArchives creates a new jar file, which isn't "fat"!我使用 build.gradle 中的任务创建了一个 fatJar,但是 uploadArchives 创建了一个新的 jar 文件,它不是“胖”!

  • so, I would either like to add the fatJar task to my uploadArchives function,所以,我想将 fatJar 任务添加到我的uploadArchives function,

OR或者

  • suppress the 'jar' task in uploadArchives, so it doesn't mess up the "fat" jar that I already have.抑制 uploadArchives 中的“jar”任务,因此它不会弄乱我已经拥有的“胖”jar。 I have tried "jar,enabled = boolean variable".我试过“jar,enabled = boolean 变量”。 but I can't set it to "false"...但我不能将其设置为“假”...

Either of these two options should be easy in a sensible language, but I can't get either to work!这两个选项中的任何一个都应该在合理的语言中很容易,但我不能让任何一个工作! Help would be appreciated!帮助将不胜感激!

If you are going to use maven for building the jar, then you need to include all the dependencies as you have in your gradle build def.如果您打算使用 maven 来构建 jar,那么您需要像在 gradle 构建定义中一样包含所有依赖项。

If you want the jar to be runnable with java -jar my.jar then, additionally you need to use some build plugin to do that for you.如果您希望 jar 可以使用java -jar my.jar运行,那么您还需要使用一些构建插件来为您执行此操作。

You can find more details here您可以在此处找到更多详细信息

Turned out to be so simple: Turned out to be the second option above:原来如此简单:原来是上面的第二个选项:

"... suppress the 'jar' task in uploadArchives, so it doesn't mess up the "fat" jar that I already have. ..." “......在uploadArchives中抑制'jar'任务,所以它不会弄乱我已经拥有的“胖”jar......”

Add -x jar to the command line for uploadArchives!-x jar添加到用于上传存档的命令行!

Thanks anyway, @samvel1024 !无论如何,谢谢@samvel1024!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM