gpt4 book ai didi

java - Maven 没有拉动我的依赖

转载 作者:行者123 更新时间:2023-11-30 08:04:22 25 4
gpt4 key购买 nike

我有

mvn依赖:解决

[INFO] [dependency:resolve {execution: default-cli}]
[INFO]
[INFO] The following files have been resolved:
[INFO] junit:junit:jar:3.8.1:test
[INFO] org.jsoup:jsoup:jar:1.8.2:compile

在 pom.xml 中

 39   <dependency>                                                                  
40 <groupId>org.jsoup</groupId>
41 <artifactId>jsoup</artifactId>
42 <version>1.8.2</version>
43 </dependency>
44 </dependencies>

但是运行代码时

java -jar /home/andref/AndroidStudioProjects/PostCrossJsoup/postcrossing-jsoup/target/postcrossing-jsoup-1.0-SNAPSHOT.jar

我明白了

Hello World!
class com.far.postcrossing.jsoup.Connect Connect fetch https://www.postcrossing.com method GET
Exception in thread "main" java.lang.NoClassDefFoundError: org/jsoup/Jsoup
at com.far.postcrossing.jsoup.Connect.fetch(Connect.java:57)
at com.far.postcrossing.jsoup.Connect.getCSRF(Connect.java:37)
at com.far.postcrossing.jsoup.Auth.goAuth(Auth.java:45)
at com.far.postcrossing.jsoup.App.main(App.java:13)
Caused by: java.lang.ClassNotFoundException: org.jsoup.Jsoup
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 4 more

此异常未找到依赖项

    <configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.far.postcrossing.jsoup.App</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>

最佳答案

根据配置,您的项目具有对 jsoup 的编译依赖项。

您的项目在应用程序执行期间失败。如果您确实需要jsoup在编译过程中,如果maven没有下载/解析jsoup,编译阶段就会失败。依赖性。

更有可能的是你没有正确配置程序集插件,甚至使用了错误的jar(没有依赖项的jar)。

根据Maven Assembly Plugin Page具有依赖项的 jar 的默认名称是 <projectname>-<version>-jar-with-dependencies.jar

来自Maven Assembly Plugin Page :

Then, to create a project assembly, simple execute the normal package phase from the default lifecycle: you need to attach it with a phase explicitly Execution: Building an Assembly

mvn package When this build completes, you should see a file in the target directory with a name similar to the following:

target/sample-1.0-SNAPSHOT-jar-with-dependencies.jar

在你的情况下,预期的 jar 是这样的: target/postcrossing-jsoup-1.0-SNAPSHOT-jar-with-dependencies.jar

关于java - Maven 没有拉动我的依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31369447/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com