【问题标题】:Jedis ClassNotFound and NoClassDefFoundErrorJedis ClassNotFound 和 NoClassDefFoundError
【发布时间】:2023-03-20 06:11:01
【问题描述】:

我为数据可视化工具开发了一个插件。现在我想在里面使用redis。当我在另一个项目(不在我的插件内)中尝试从here 获取的以下 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/JedisCaused by: java.lang.NoClassDefFoundError: redis/clients/jedis/Jedis 错误。为了将我的插件安装到这个数据可视化工具中。我需要创建一个我所做的 jar 文件,并且它在不添加 jedit 部分的情况下运行良好。

我正在使用 IntelliJ Idea,我创建了一个工件并从顶部菜单中的 build - build artifact 选项卡中构建它。我还在 pom.xml 中添加了 jedis jar 文件作为依赖项(这是一个 maven 项目),我将它添加为项目结构中的库,并添加了 jedis jar 文件作为提取目录和库以及项目结构的 artifacts 选项卡菜单。然后我将 jedis jar 文件添加到我的项目 .classpath 文件中,如下所示:

    <classpathentry kind="src" path="src/main/resources/jedis-2.1.0-sources.jar" including="**/*.java"/>

所以当我打开我的 jar 文件时,我可以看到“redis/clients/jedis”路径中有 Jedis.java 文件。我的 jar 文件的根路径中还有 jedis jar 文件。但即使这样也行不通。它在 runtime 给出了上述错误。我哪里做错了?

【问题讨论】:

    标签: java maven redis cytoscape.js


    【解决方案1】:

    经过长时间的研究和“实验”,我解决了它。这是我添加 pom.xml 以摆脱它的部分。而且我还使用“mvn package”命令创建 jar 文件,而不是从 IntelliJ IDEA 界面。

    <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>
    

    【讨论】:

      猜你喜欢
      • 2011-12-07
      • 2022-10-01
      • 2018-12-10
      • 1970-01-01
      • 1970-01-01
      • 2015-12-27
      • 2012-05-10
      • 2018-11-08
      • 2012-09-08
      相关资源
      最近更新 更多