我在使用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...
它编译良好。有人可以解释我在做什么错吗?我从未遇到过这样的问题。
最佳答案
这条线RedisPubSubSpout spout = RedisPubSubSpout("redis://129.196.196.166", 6379, "WebhookEvents");
应该RedisPubSubSpout spout = new RedisPubSubSpout("redis://129.196.196.166", 6379, "WebhookEvents");
您缺少new
运算符
您当前的语法正在尝试查找名为RedisPubSubSpout
的局部函数