首页 > 解决方案 > Stromcrawler 1.16 中的构建失败

问题描述

我正在使用stormcrawler 1.16、apachestorm 1.2.3、maven 3.6.3和jdk 1.8。

我已经使用下面的 artifact 命令创建了项目 -

mvn archetype:generate -DarchetypeGroupId=com.digitalpebble.stormcrawler -Darche typeArtifactId=storm-crawler-elasticsearch-archetype -DarchetypeVersion=LATEST

当我运行 mvn clean package 命令时,我收到此错误 -

   /crawler$ mvn clean package
 [INFO] Scanning for projects...
 [INFO] 
  [INFO] -------------------------< com.storm:crawler >--------------------------
 [INFO] Building crawler 1.0-SNAPSHOT  
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ crawler ---
[INFO] Deleting /home/ubuntu/crawler/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ crawler ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ crawler ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /home/ubuntu/crawler/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /home/ubuntu/crawler/src/main/java/com/cnf/245/ESCrawlTopology.java:[19,16] ';' 
expected
[INFO] 1 error 
[INFO] -------------------------------------------------------------  
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.407 s
[INFO] Finished at: 2020-06-29T20:40:46Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.2:compile 
 (default-compile) on project crawler: Compilation failure
 [ERROR] /home/ubuntu/crawler/src/main/java/com/cnf/245/ESCrawlTopology.java:[19,16] ';' 
 expected
 [ERROR] 
 [ERROR] -> [Help 1]
 [ERROR] 
 [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
 [ERROR] Re-run Maven using the -X switch to enable full debug logging.
 [ERROR] 
 [ERROR] For more information about the errors and possible solutions, please read the 
  following articles:
 [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

我还没有编辑 pom.xml 文件。

这是 ESCrawlTopology.java 文件的内容 -

    package com.cnf.245;
    import org.apache.storm.metric.LoggingMetricsConsumer;
    import org.apache.storm.topology.TopologyBuilder;     
    import org.apache.storm.tuple.Fields;

    import com.digitalpebble.stormcrawler.ConfigurableTopology;
    import com.digitalpebble.stormcrawler.Constants;
    import com.digitalpebble.stormcrawler.bolt.FetcherBolt;
    import com.digitalpebble.stormcrawler.bolt.JSoupParserBolt;
    import com.digitalpebble.stormcrawler.bolt.SiteMapParserBolt;
    import com.digitalpebble.stormcrawler.bolt.URLFilterBolt;
    import com.digitalpebble.stormcrawler.bolt.URLPartitionerBolt;
    import 
    com.digitalpebble.stormcrawler.elasticsearch.bolt.DeletionBolt;
    import  
    com.digitalpebble.stormcrawler.elasticsearch.bolt.IndexerBolt;
    import 


 com.digitalpebble.stormcrawler.elasticsearch.metrics.MetricsConsumer;
        import 
 

com.digitalpebble.stormcrawler.elasticsearch.metrics.StatusMetricsBolt;
        import 
 

com.digitalpebble.stormcrawler.elasticsearch.persistence.AggregationSpout;
       import com.digitalpebble.stormcrawler.elasticsearch.persistence.StatusUpdaterBolt;
       import com.digitalpebble.stormcrawler.spout.FileSpout;
       import com.digitalpebble.stormcrawler.util.ConfUtils;
        import com.digitalpebble.stormcrawler.util.URLStreamGrouping;

     /**
 * Dummy topology to play with the spouts and bolts on ElasticSearch
 */
public class ESCrawlTopology extends ConfigurableTopology {

    public static void main(String[] args) throws Exception {
        ConfigurableTopology.start(new ESCrawlTopology(), args);
    }

    @Override
    protected int run(String[] args) {
        TopologyBuilder builder = new TopologyBuilder();

        int numWorkers = ConfUtils.getInt(getConf(), "topology.workers", 1);

        if (args.length == 0) {
            System.err.println("ESCrawlTopology seed_dir file_filter");
            return -1;
        }

        // set to the real number of shards ONLY if es.status.routing is set to
        // true in the configuration
        int numShards = 1;

        builder.setSpout("filespout", new FileSpout(args[0], args[1], true));

        Fields key = new Fields("url");

        builder.setBolt("filter", new URLFilterBolt())
                .fieldsGrouping("filespout", Constants.StatusStreamName, key);

        builder.setSpout("spout", new AggregationSpout(), numShards);

        builder.setBolt("status_metrics", new StatusMetricsBolt())
                .shuffleGrouping("spout");

        builder.setBolt("partitioner", new URLPartitionerBolt(), numWorkers)
                .shuffleGrouping("spout");

        builder.setBolt("fetch", new FetcherBolt(), numWorkers)
                .fieldsGrouping("partitioner", new Fields("key"));

        builder.setBolt("sitemap", new SiteMapParserBolt(), numWorkers)
                .localOrShuffleGrouping("fetch");

        builder.setBolt("parse", new JSoupParserBolt(), numWorkers)
                .localOrShuffleGrouping("sitemap");

        builder.setBolt("indexer", new IndexerBolt(), numWorkers)
                .localOrShuffleGrouping("parse");

        builder.setBolt("status", new StatusUpdaterBolt(), numWorkers)
                .fieldsGrouping("fetch", Constants.StatusStreamName, 
         key)
                .fieldsGrouping("sitemap", Constants.StatusStreamName, 
         key)
                .fieldsGrouping("parse", Constants.StatusStreamName, 
        key)
                .fieldsGrouping("indexer", Constants.StatusStreamName, 
        key)
                .customGrouping("filter", Constants.StatusStreamName,
                        new URLStreamGrouping());

        builder.setBolt("deleter", new DeletionBolt(), numWorkers)
                .localOrShuffleGrouping("status",
                        Constants.DELETION_STREAM_NAME);

        conf.registerMetricsConsumer(MetricsConsumer.class);
        conf.registerMetricsConsumer(LoggingMetricsConsumer.class);

        return submit("crawl", conf, builder);
          }
       }

我将 com.cnf.245 放在 groupId 中,将 crawler 放在 articfactId 中。

有人请解释导致此错误的原因?

标签: stormcrawler

解决方案


你能粘贴ESCrawlTopology.java的内容吗?您是否将com.cnf.245设置为包名?

模板类在执行原型的过程中被重写,包名被替换,可能是您设置的值破坏了模板。

编辑:您不能在 Java 中的包名称中使用数字。请参阅在 java 中使用数字作为包名

使用不同的包名称和 groupID。


推荐阅读