当前位置: 首页 > 知识库问答 >
问题:

maven依赖项java.util.function未正确加载函数类

李鸿
2023-03-14
package com.hf.arm;

import org.apache.spark.SparkConf;
import java.util.Arrays;
import java.util.List;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.mllib.fpm.AssociationRules;
import org.apache.spark.mllib.fpm.FPGrowth;
import org.apache.spark.mllib.fpm.FPGrowthModel;
public class App 
{
    public static void main( String[] args )
    {
        SparkConf conf = new SparkConf().setAppName("FP-growth Example");
        JavaSparkContext sc = new JavaSparkContext(conf);
        JavaRDD<String> data = sc.textFile("/Users/lincolnsmith/Table_csv/sample_fpgrowth.txt");
    }
}
package com.hf.arm;

import org.apache.spark.SparkConf;
import java.util.Arrays;
import java.util.List;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.mllib.fpm.AssociationRules;
import org.apache.spark.mllib.fpm.FPGrowth;
import org.apache.spark.mllib.fpm.FPGrowthModel;

public class App 
{
    public static void main( String[] args )
    {
    SparkConf conf = new SparkConf().setAppName("FP-growth Example");
    JavaSparkContext sc = new JavaSparkContext(conf);
    JavaRDD<String> data = sc.textFile("/Users/lincolnsmith/Table_csv/sample_fpgrowth.txt");
    JavaRDD<List<String>> transactions = data.map(
      new Function<String, List<String>>() {
        public List<String> call(String line) {
          String[] parts = line.split(" ");
          return Arrays.asList(parts);
        }
      }
    );
    FPGrowth fpg = new FPGrowth()
      .setMinSupport(0.2)
      .setNumPartitions(10);
    FPGrowthModel<String> model = fpg.run(transactions);
    for (FPGrowth.FreqItemset<String> itemset: model.freqItemsets().toJavaRDD().collect()) {
      System.out.println("[" + itemset.javaItems() + "], " + itemset.freq());
    }
    double minConfidence = 0.8;
    for (AssociationRules.Rule<String> rule
        : model.generateAssociationRules(minConfidence).toJavaRDD().collect()) {
      System.out.println(
        rule.javaAntecedent() + " => " + rule.javaConsequent() + ", " + rule.confidence());
    }

    }
}
import java.util.function.Function;
<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.hf.arm</groupId>
  <artifactId>arm</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>arm</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency> <!-- Spark dependency -->
        <groupId>org.apache.spark</groupId>
        <artifactId>spark-core_2.10</artifactId>
        <version>1.5.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.spark</groupId>
    <artifactId>spark-mllib_2.10</artifactId>
    <version>1.5.1</version>
    </dependency>
    <dependency>
    <groupId>net.sf.m-m-m</groupId>
    <artifactId>mmm-util-backport-java.util.function</artifactId>
    <version>1.0.1</version>
    </dependency>
  </dependencies>
<build>
<plugins>
  <plugin>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.3</version>
      <configuration>
          <source>1.7</source>
          <target>1.7</target>
      </configuration>
  </plugin>
</plugins>
</build>
</project>
Lincolns-MacBook-Pro:arm lincolnsmith$ mvn package
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building arm 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ arm ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/lincolnsmith/Table_csv/arm/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ arm ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /Users/lincolnsmith/Table_csv/arm/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /Users/lincolnsmith/Table_csv/arm/src/main/java/com/hf/arm/App.java:[6,11] '.' expected
[ERROR] /Users/lincolnsmith/Table_csv/arm/src/main/java/com/hf/arm/App.java:[6,12] ';' expected
[ERROR] /Users/lincolnsmith/Table_csv/arm/src/main/java/com/hf/arm/App.java:[6,16] class, interface, or enum expected
[ERROR] /Users/lincolnsmith/Table_csv/arm/src/main/java/com/hf/arm/App.java:[6,17] class, interface, or enum expected
[INFO] 4 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.241 s
[INFO] Finished at: 2015-10-14T10:05:13-04:00
[INFO] Final Memory: 19M/437M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project arm: Compilation failure: Compilation failure:
[ERROR] /Users/lincolnsmith/Table_csv/arm/src/main/java/com/hf/arm/App.java:[6,11] '.' expected
[ERROR] /Users/lincolnsmith/Table_csv/arm/src/main/java/com/hf/arm/App.java:[6,12] ';' expected
[ERROR] /Users/lincolnsmith/Table_csv/arm/src/main/java/com/hf/arm/App.java:[6,16] class, interface, or enum expected
[ERROR] /Users/lincolnsmith/Table_csv/arm/src/main/java/com/hf/arm/App.java:[6,17] class, interface, or enum expected
[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
Lincolns-MacBook-Pro:arm lincolnsmith$ java -version
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)

共有1个答案

江天宇
2023-03-14

实际上,您不需要backport包,因为函数属于Spark API,而不属于Java8 API。请尝试以下操作:

JavaRDD<List<String>> transactions = data.map(
    new org.apache.spark.api.java.function.Function<String, List<String>>() {
        public List<String> call(String line) throws Exception {
            String[] parts = line.split(" ");
            return Arrays.asList(parts);
        }
    }
);

然后可以使用正确的类路径构建和运行应用程序:

mvn clean compile exec:java -Dexec.mainClass="com.hf.App"

它工作得很好(在我的情况下达到了预期的结果):

...
org.apache.spark.SparkException: A master URL must be set in your configuration
        at org.apache.spark.SparkContext.<init>(SparkContext.scala:394)
        ...
 类似资料:
  • 基本上,我有一个spring boot项目建设与Gradle。该项目有一个包含另外4个子模块的根项目。根项目settings.gradle如下所示: app模块包含spring-引导-分级-插件,并公开了一些API。 我想做的是创建proj-integration-tests子模块,它只包含集成测试。问题从这里开始,因为我需要proj-app依赖关系。 所以在proj-integration-te

  • 我正在eclipse中建立一个项目。此项目通过命令行成功构建(所有、、)等命令都运行良好。同时在STS或Eclipse上设置此项目。我看到有些依赖项没有下载,尽管它们存在于中。但是,在maven存储库中搜索它们,并将jar下载到我的本地计算机,然后将它们添加到构建路径中,就可以在Eclipse上运行。 我们需要对eclipse做什么来确保它从存储库下载所有的依赖项。 我的POM:

  • 我在使用Maven 3,IntelliJ IDEA的最新版本,java 8和kotlin 1.5时遇到了一些奇怪的行为: 我有一个静态编程语言jar作为本地文件系统的依赖项。 当创建一个新的Java项目,添加maven框架并将依赖项(带有系统范围)添加到我的POM时,它会正确加载到我的IntelliJ类路径中,我可以在我的代码中使用它。 创建静态编程语言项目时,添加maven框架并将具有相同POM

  • 我面临的第一个问题是提供的依赖关系,该依赖关系总是作为运行时写入pom.xml。 第二个问题是动态版本,我使用它来进行较小的版本更改。Maven和Gradle有不同的符号,maven-publish只是将Gradle的符号写入pom.xml 下面是我的例子:

  • 如何从其 GitHub 存储库(该库使用 Maven 作为构建系统)添加 Java 库作为依赖项添加到我的 Maven 项目中?我可以在不下载和编译库的情况下执行此操作吗?

  • 我们用Maven和Tycho构建了一个Eclipse插件。然而,目前我们仍然通过一堆手动添加的JAR文件而不是Maven来提供所有的项目依赖。这是由于以下原因:(1)依赖项不能通过标准的Eclipse更新站点获得(至少不能在当前版本中获得),(2)依赖项不能作为捆绑包获得。 这些依赖项中最大的部分是Selenium库(API,远程,特定于浏览器的库及其传递依赖项,例如Guava等)。 我浪费了几个

  • 如何将此WorldEdit依赖项添加到Maven项目中?http://maven.sk89q.com/artifactory/repo/com/sk89q/worldedit/worldedit-bukkit/我需要6.1.1快照。 是否有算法来获取组ID工件ID和版本?

  • 错误:无法初始化主类com.companyname.bank.App,原因是:java.lang.NoClassDefFoundError:org/apache/http/client/ResponseHandler 我在pom.xml文件中添加了依赖项,在/src/lib中也添加了相关的.jar文件之后,这个报告一直出现。真的很困惑,不知道怎么解决。 请帮我一把。谢谢。 以下是我的操作流程: >