我为一个数据可视化工具开发了一个插件。现在我想在里面用红色。当我尝试在另一个项目(不是在我的插件中)中从这里获取的下面的redis代码时,它工作得很好。
//Connecting to Redis server on localhost
Jedis jedis = new Jedis("localhost");
System.out.println("Connection to server sucessfully");
//check whether server is running or not
System.out.println("Server is running: "+jedis.ping()); 但是当我在插件中使用Jedis时,我得到了Caused by: java.lang.NoClassDefFoundError: redis/clients/jedis/Jedis和Caused by: java.lang.NoClassDefFoundError: redis/clients/jedis/Jedis错误。为了将我的插件安装到这个数据可视化工具上。我需要创建一个jar文件,这是我所做的,它运行良好,无需添加jedit部件。
我使用的是IntelliJ的想法,我创建了一个工件,并在顶部菜单中的Build-Build工件选项卡中构建了id。我还在pom.xml中添加了jedis文件作为依赖项(这是一个maven项目),我从项目结构中将它添加为库,并将jedis文件作为提取目录和库添加到项目结构菜单的工件选项卡中。然后我将jedis文件添加到我的项目.classpath文件中,如下所示:
<classpathentry kind="src" path="src/main/resources/jedis-2.1.0-sources.jar" including="**/*.java"/>因此,当我打开jar文件时,我可以看到在“redis/client/jedis”路径中有Jedis.java文件。我的jar文件的根路径中也有jedis文件。但即便如此,也不起作用。它在运行时中给出了上面的错误。我哪里做错了?
发布于 2018-04-15 07:49:49
经过研究和“实验”,我解决了这个问题。下面是我添加pom.xml的部分,以消除这个问题。我还使用"mvn包“命令创建jar文件,而不是从IntelliJ IDEA接口创建jar文件。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8.0_161</source>
<target>1.8.0_161</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>App.CytoVisProject</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>https://stackoverflow.com/questions/49805456
复制相似问题