[英]CouchDB4j/ mvn dependencies are missing
I am having trouble setting up a connection to my local CouchDB programmatically. 我无法以编程方式设置与本地CouchDB的连接。
I am using couchDb4j- and things seem to look good, until I run and try to connect to the DB. 我正在使用ouchDb4j-,在我运行并尝试连接到数据库之前,一切看起来都不错。
My console is throwing the following error: 我的控制台抛出以下错误:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/http/params/HttpParams
[...]
Caused by: java.lang.ClassNotFoundException: org.apache.http.params.HttpParams
Since my small application is not finding a class, I've checked my dependencies- everything should be fine. 由于我的小型应用程序未找到类,因此我检查了我的依赖关系-一切都很好。 I have:
我有:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.0-beta3</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
Which should include all necessary http specific .jar (especially the first one should include the httpParams binaries; source: http://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore/4.0-beta3 ). 其中应包含所有必需的特定于http的.jar(尤其是第一个应包含httpParams二进制文件;源: http ://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore/4.0-beta3)。
To prevent from including wrong binaries cached on my system, I am running the following: 为了防止包括错误的二进制文件缓存在我的系统上,我正在运行以下命令:
mvn clean && mvn package mvn clean && mvn软件包
I've also deleted my .m2 folder. 我还删除了.m2文件夹。
Googling around gave me the hint that my classpath may be wrong leading to missing dependencies in runtime. 到处搜寻会提示我我的类路径可能是错误的,导致运行时缺少依赖项。 But I have set up my classpath in my pom;
但是我已经在pom中设置了我的类路径; see here:
看这里:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>Packagename.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
Hopefully anyone can give me one idea so that I can fix this issue :) 希望任何人都可以给我一个主意,以便我可以解决此问题:)
Best regards. 最好的祝福。
Add these dependencies inside plugin declaration like this: 将这些依赖项添加到插件声明中,如下所示:
<plugin>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>
<dependencies>
...
</dependencies>
</plugin>
Plugins have their own classpath 插件有自己的类路径
Found the solution. 找到了解决方案。
The problem were missing dependencies during execution. 问题是执行期间缺少依赖项。
To make sure, that all necessary files are binded during runtime, I had to include the following plugin: 为了确保在运行时绑定了所有必需的文件,我必须包括以下插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
which, if I got it right, binds on an "uber" jar all dependencies... Source: https://maven.apache.org/plugins/maven-shade-plugin/ 如果我做对的话,它将所有依赖项绑定到“超级” jar上...来源: https : //maven.apache.org/plugins/maven-shade-plugin/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.