[Hello, world!] Remember storm-starter's miserable debugging experience in a well-known IDE, hellostorm-starter
Background
I recently received such a question:
Storm generates a message tree based on the Topology when processing messages. How does Storm track each message, ensure that messages are not lost, and implement the message resend mechanism?
Although I have replied, I want to check the source code of storm. If it is so static, debug it. Well, create a local environment for debugging.
Let's take a look at the maven build:
mvn -f pom.xml clean install
After storm compilation and packaging is completed, storm-starter compilation and packaging is followed. Everything went well. Let's take a look:
${STORM_HOME}/bin/storm jar ${STORM_JAR} ${STORM_STARTER_JAR} storm.starter.WordCountTopology
The result is successful. It's not a hello world!
Create a local environment and import the storm-starter source code to Intellij IDEA in maven mode. Note that From this time on, we will start to feel sad.
Hello, world!
After I imported the IDE, I was very interested.F5
And then:
This Nima said it was a tough fight!
Depends on the dependency"Suitable for all"Ah, ClassPath"Suitable for all"Ah, otherwise the compilation will fail. It will run for Mao! No! Start! Come!
This is the same operation. It is appropriate in eclipse to run a variety of tasks. Why did Mao go wrong in Intellij IDEA?
How exceptions are generated
Well, now that you are a fan of the well-known IDE, you must be ashamed and brave.
Then, let's see how exceptions are generated.
As shown in the figure above, exceptions are basically summarized.NoClassDefFound
The generated path.
The exception details are as follows:
Note:
JVM_GetClassDelaredMethods
Is the method in JVM. Find the entry function.main
This method is called.
- Next, this method calls the process of verifying the bytecode:
verify_code
.
- Found useful
backtype.storm.topology.IRichBolt
Interface..class
File:
If we runjava -cp . xxx
, Through-cp
Or-classpath
Parameter specifiedclasspath
, Then this.class
Will be found. Then enterparse
.
- Sadly, IDEA running or Debugging commands
f5->run
, Nobacktype.storm.topology.IRichBolt.class
Jar packagestorm-core.jar
Add classpath...
So, since there is a search*.class
The process is as follows:
Briefly describe:
How to handle exceptions
Okay, the exception is generated clearly. There is another problem, that__pending_exception
When will it be processed?
See:
A brief description is provided:
Why is my face beaten?
Here, the nature and handling of exceptions are clear.
Below is a simple summary:
/* Pseudo code */main/* main */-> createJVM ()/* Create JVM */-> loadMainClass () /* load the specified $ mainClass file. This is a class file */-> findMethod ("main")/* Find the main method in $ mainClass, the main */-> getMethodFromJVM ()/* of the program written in java is not cached. Ask the JVM */-> classLoader. loadFromFile ()/* Find in classpath. class file */-> not found, set NoClassDefFound exception.
However, why does Intellij IDEA not setstorm-core.jar
Includeclasspath
What about it?
In other words: Why is the face beaten ??
The reason for face recognition is simple:
1.F5->run
, Make/compile/build first, and then run.
2. Set the dependent scopeprovided
This setting only adds the dependent jar package to the classpath during the compilation stage. In the runtime stage, the jar package is not added to the classpath.
The solution is also very simple:
If mvn is not used, but debugging/running in IDE, select the scope of the dependent jar packagecompile
Well, you won't be beaten!
Check whether it is correct?
Postscript
End.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.