0
votes

While trying to learn how to use storm. I decided to compile my own instance of the well known WordCount Topology to see how it is done. The code is 100% identical to the example's one. (https://github.com/apache/storm/blob/master/examples/storm-starter/src/jvm/org/apache/storm/starter/WordCountTopology.java)

However whenever I try to run the jar I get the error saying I could not find or load the main class. I can run the default example jar that comes bundled with storm with no problems (like in bellow), so it shouldn't be a calling syntax problem.

bin/storm jar lib/"name".jar "classpath"

Maven creates the jar with no problem, initially I assumed I wasn't excluding the storm dependency properly in the pom file but It should be like this, right?

<dependencies>
    <dependency>
        <groupId>org.apache.storm</groupId>
        <artifactId>storm-core</artifactId>
        <version>1.0.2</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

This is perhaps is a vague question, but to be honest not sure where to tackle it since the code is the same, so generating a successful jar shouldn't be an issue, right?

2

2 Answers

0
votes

First of all, remove <scope>provided</scope> from your dependency.
Second, what you need here is an executable jar. By default, maven does not produce an executable jar. So, when you are building your jar, you have to specify the main class. This can be done using the Maven Assembly Plugin

<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.6</version>
        <configuration>
          [...]
          <archive>
            <manifest>
              <mainClass>org.sample.App</mainClass>      // specify your main class here.
            </manifest>
          </archive>
        </configuration>
        [...]
      </plugin>
      [...]
</project>

This will produce an executable jar.

0
votes
  1. storm jar requires two parameters; the first one: the jar; the second one: the full qualified name to the main class to run.
  2. If you want to exclude the storm dependency, the error should be different; although the pom.xml is more complicated than what you have. See this answer.
  3. Sometimes, you have to specify the full path to the jar.

In summary:

storm jar /full/path/to/your/jar com.foo.bar.MainClass