maven - 执行Java类时发生异常,ClassNotFoundException

问题描述 投票:0回答:1

我正在尝试创建并运行 Apache Beam 管道,但每当我运行

mvn compile exec:java -D"exec.mainClass"="App"
时都会收到此错误。尽管在
mvn compile
和/或
mvn clean install
之后我没有收到
mvn clean package
的错误,但我无法运行我的管道。

错误信息:

...
Caused by: java.lang.ClassNotFoundException: org.apache.beam.sdk.testing.SerializableMatcher
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  10.470 s
[INFO] Finished at: 2024-10-13T01:28:06+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:3.1.0:java (default-cli) on project beam-java-starter: An exception occurred while executing the Java class. org/apache/beam/sdk/testing/SerializableMatcher: org.apache.beam.sdk.testing.SerializableMatcher

我将“org.apache.beam”“beam-sdks-java-test-utils”(版本2.59.0)添加到pom.xml以解决此错误,但仍然出现。 (https://beam.apache.org/releases/javadoc/current/org/apache/beam/sdk/testing/SerializedMatcher.html

完整的pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!-- 
  Copyright 2022 Google LLC

  Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
  https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
  <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
  option. This file may not be copied, modified, or distributed
  except according to those terms.
 -->
<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.example</groupId>
  <artifactId>beam-java-starter</artifactId>
  <version>1</version>

  <properties>
    <maven.compiler.source>17</maven.compiler.source>
    <maven.compiler.target>17</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.10.1</version>
      </plugin>

      <!-- Run the app through mvn. -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>3.1.0</version>
        <configuration>
          <mainClass>com.example.App</mainClass>
          <cleanupDaemonThreads>false</cleanupDaemonThreads>
        </configuration>
      </plugin>

      <!-- JUnit 4 testing integration. -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.4.0</version>
      </plugin>

      <!-- Package self-contained jar file. -->
      <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.6.0</version>
                <executions>
                  <execution>
                    <phase>package</phase> 
                    <goals>
                        <goal>single</goal>
                    </goals>
                  </execution>
                </executions>
                <configuration>
                    <archive>
                      <manifest>
              <mainClass>com.example.App</mainClass>
                      </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>
    </plugins>
  </build>

  <dependencies>
      <!-- Apache Beam BigQuery IO -->
    <dependency>
        <groupId>org.apache.beam</groupId>
        <artifactId>beam-sdks-java-io-google-cloud-platform</artifactId>
        <version>2.59.0</version>
    </dependency>

    <!-- Apache Beam JDBC IO -->
    <dependency>
        <groupId>org.apache.beam</groupId>
        <artifactId>beam-sdks-java-io-jdbc</artifactId>
        <version>2.59.0</version>
    </dependency>

    <!-- Google Cloud Platform Libraries -->
    <dependency>
        <groupId>com.google.cloud</groupId>
        <artifactId>google-cloud-bigquery</artifactId>
        <version>2.43.0</version>
    </dependency>

    <dependency>
      <groupId>com.google.cloud.dataflow</groupId>
      <artifactId>google-cloud-dataflow-java-sdk-all</artifactId>
      <version>2.5.0</version>
    </dependency>

    <!-- Microsoft SQL Server JDBC Driver -->
    <dependency>
        <groupId>com.microsoft.sqlserver</groupId>
        <artifactId>mssql-jdbc</artifactId>
        <version>12.8.0.jre11</version>
    </dependency>

    <!-- Apache Beam Testing -->  
    <dependency>
        <groupId>org.apache.beam</groupId>
        <artifactId>beam-sdks-java-test-utils</artifactId>
        <version>2.59.0</version>
    </dependency>


    <!-- App dependencies -->
    <dependency>
      <groupId>org.apache.beam</groupId>
      <artifactId>beam-sdks-java-core</artifactId>
      <version>2.59.0</version>
    </dependency>

    <dependency>
      <groupId>org.apache.beam</groupId>
      <artifactId>beam-runners-direct-java</artifactId>
      <version>2.59.0</version>
      <scope>runtime</scope>
    </dependency>

    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-jdk14</artifactId>
      <version>1.7.32</version>
    </dependency>

    <!-- Test dependencies -->
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>5.11.2</version>
        <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.13.2</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.hamcrest</groupId>
      <artifactId>hamcrest</artifactId>
      <version>2.2</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

java maven apache-beam
1个回答
0
投票

是否有可能是依赖没有正确下载,现在 Maven 的 .m2 目录中有一些无法使用的文件?

尝试清理 $HOME/.m2/repository (所有文件或此类所在的依赖项),然后重试。

© www.soinside.com 2019 - 2024. All rights reserved.