Maven的新功能:无法找到符号错误

时间:2015-01-29 18:45:53

标签: java maven

我在使用Maven编译基本java应用程序时遇到问题。这是我第一次使用该程序,该程序被选择用于依赖管理。

申请如下

package com.ender.storm;

import com.ender.storm.RedisPubSubSpout;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        RedisPubSubSpout spout = RedisPubSubSpout("redis://129.196.196.166", 6379, "WebhookEvents");
        System.out.println( "Hello World!" );
    }
}

从中复制了RedisPubSubSpout类 https://github.com/stormprocessor/storm-redis-pubsub/blob/master/src/jvm/yieldbot/storm/spout/RedisPubSubSpout.java

并放在与App类相同的文件夹中。

编辑:我的文件夹中的类如下

package com.ender.storm;

import static backtype.storm.utils.Utils.tuple;

import java.util.Map;
import java.util.concurrent.LinkedBlockingQueue;

import org.apache.log4j.Logger;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.JedisPubSub;

import backtype.storm.spout.SpoutOutputCollector;
import backtype.storm.task.TopologyContext;
import backtype.storm.topology.base.BaseRichSpout;
import backtype.storm.topology.OutputFieldsDeclarer;
import backtype.storm.tuple.Fields;
import backtype.storm.utils.Utils;

public class RedisPubSubSpout extends BaseRichSpout {

    static final long serialVersionUID = 737015318988609460L;
    static Logger LOG = Logger.getLogger(RedisPubSubSpout.class);

    SpoutOutputCollector _collector;
    final String host;
    final int port;
    final String pattern;
    LinkedBlockingQueue<String> queue;
    JedisPool pool;

    public RedisPubSubSpout(String host, int port, String pattern) {
        this.host = host;
        this.port = port;
        this.pattern = pattern;
    }

    class ListenerThread extends Thread {
        LinkedBlockingQueue<String> queue;
        JedisPool pool;
        String pattern;

        public ListenerThread(LinkedBlockingQueue<String> queue, JedisPool pool, String pattern) {
            this.queue = queue;
            this.pool = pool;
            this.pattern = pattern;
        }

        public void run() {

            JedisPubSub listener = new JedisPubSub() {

                @Override
                public void onMessage(String channel, String message) {
                    queue.offer(message);
                }

                @Override
                public void onPMessage(String pattern, String channel, String message) {
                    queue.offer(message);
                }

                @Override
                public void onPSubscribe(String channel, int subscribedChannels) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onPUnsubscribe(String channel, int subscribedChannels) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onSubscribe(String channel, int subscribedChannels) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onUnsubscribe(String channel, int subscribedChannels) {
                    // TODO Auto-generated method stub

                }
            };

            Jedis jedis = pool.getResource();
            try {
                jedis.psubscribe(listener, pattern);
            } finally {
                pool.returnResource(jedis);
            }
        }
    };

    public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
        _collector = collector;
        queue = new LinkedBlockingQueue<String>(1000);
        pool = new JedisPool(new JedisPoolConfig(),host,port);

        ListenerThread listener = new ListenerThread(queue,pool,pattern);
        listener.start();

    }

    public void close() {
        pool.destroy();
    }

    public void nextTuple() {
        String ret = queue.poll();
        if(ret==null) {
            Utils.sleep(50);
        } else {
            _collector.emit(tuple(ret));            
        }
    }

    public void ack(Object msgId) {
        // TODO Auto-generated method stub

    }

    public void fail(Object msgId) {
        // TODO Auto-generated method stub

    }

    public void declareOutputFields(OutputFieldsDeclarer declarer) {
        declarer.declare(new Fields("message"));
    }

    public boolean isDistributed() {
        return false;
    }
}

错误日志显示

[INFO] Compiling 2 source files to <file_path>/projects/mvn/Storm/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] <file_path>/projects/mvn/Storm/src/main/java/com/ender/storm/App.java:[13,34] cannot find symbol
  symbol:   method RedisPubSubSpout(java.lang.String,int,java.lang.String)
  location: class com.ender.storm.App
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE

我的maven版本是

Apache Maven 3.0.5
Maven home: /usr/share/maven
Java version: 1.7.0_75, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-7-openjdk-i386/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.13.0-44-generic", arch: "i386", family: "unix"

使用

的pom.xml文件
<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.ender.storm</groupId>
  <artifactId>Storm</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>Storm</name>
  <url>http://maven.apache.org</url>
  <build>
    <pluginManagement>
         <plugins>
             <plugin>
                 <artifactId>maven-compiler-plugin</artifactId>
                 <version>3.1</version>
                 <configuration>
                     <source>1.7</source>
                     <target>1.7</target>
                     <compilerArgument></compilerArgument>
                 </configuration>
             </plugin>
         </plugins>
    </pluginManagement>
  </build>
  <dependencies>
    <dependency>
      <groupId>org.apache.storm</groupId>
      <artifactId>storm-core</artifactId>
      <version>0.9.1-incubating</version>
    </dependency>
    <dependency>
      <groupId>redis.clients</groupId>
      <artifactId>jedis</artifactId>
      <version>2.6.0</version>
      <type>jar</type>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

我正在编译Ubuntu 14.04。

如果我注释掉喷口

//RedisPubSubSpout spout = RedisPubSubSpout...

它编译得很好。有人可以解释一下我做错了什么吗?我之前从未遇到过这样的问题。

1 个答案:

答案 0 :(得分:3)

这一行

RedisPubSubSpout spout = RedisPubSubSpout("redis://129.196.196.166", 6379, "WebhookEvents");

应该是

RedisPubSubSpout spout = new RedisPubSubSpout("redis://129.196.196.166", 6379, "WebhookEvents");

您错过了new运算符

您当前的语法是尝试查找名为RedisPubSubSpout

的本地函数