Caused by: java.lang.ClassNotFoundException: backtype.storm.topology.IRichSpout
1:初次运行Strom程序出现如下所示的错误,贴一下,方便脑补,也希望帮助到看到的小伙伴:
错误如下所示,主要问题是刚开始使用maven获取jar包的时候需要写<scope>provided</scope>,运行的时候需要把这行注释了即可,这是作用域的问题,开始需要在本地下载jar包,但是在虚拟机运行的时候已经存在这些jar包了,所以再写这句话就冲突了:
1 java.lang.NoClassDefFoundError: backtype/storm/topology/IRichSpout 2 at java.lang.Class.getDeclaredMethods0(Native Method) 3 at java.lang.Class.privateGetDeclaredMethods(Class.java:2625) 4 at java.lang.Class.getMethod0(Class.java:2866) 5 at java.lang.Class.getMethod(Class.java:1676) 6 at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494) 7 at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486) 8 Caused by: java.lang.ClassNotFoundException: backtype.storm.topology.IRichSpout 9 at java.net.URLClassLoader$1.run(URLClassLoader.java:366) 10 at java.net.URLClassLoader$1.run(URLClassLoader.java:355) 11 at java.security.AccessController.doPrivileged(Native Method) 12 at java.net.URLClassLoader.findClass(URLClassLoader.java:354) 13 at java.lang.ClassLoader.loadClass(ClassLoader.java:425) 14 at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) 15 at java.lang.ClassLoader.loadClass(ClassLoader.java:358) 16 ... 6 more 17 Exception in thread "main" 18 Process finished with exit code 1
解决方法如下所示:
贴下pom.xml文件:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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.bie</groupId> <artifactId>storm</artifactId> <version>1.0-SNAPSHOT</version> <!-- storm的依赖关系 --> <dependencies> <dependency> <groupId>org.apache.storm</groupId> <artifactId>storm-core</artifactId> <version>0.9.5</version> <!--<scope>provided</scope>--> </dependency> </dependencies> <!--如果依赖外部包,就打不进去外部包,所以需要引入下面所示--> <build> <plugins> <plugin> <!--把其他外部依赖的jar包打成一个大jar包--> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <archive> <manifest> <mainClass>com.bie.wordcount.WordCountTopologyMain</mainClass> </manifest> </archive> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> </plugins> </build> </project>
停更......
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?