【问题标题】:Cannot compile maven project无法编译maven项目
【发布时间】:2020-12-04 12:01:04
【问题描述】:

我使用来自 Confluent 的人工制品开始了一个简单的项目。但是当我尝试使用mvn clean installmvn clean package 编译项目时,我收到了类似的消息

[ERROR] C:\Users\its\git\datakmu\service-stack\stream-data-preprocessor\src\main\java\at\ac\fhsalzburg\datakmu\service\DataPreProcessor.java:[1]
        package at.ac.fhsalzburg.datakmu.service;
        ^
The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files
[ERROR] C:\Users\its\git\datakmu\service-stack\stream-data-preprocessor\src\main\java\at\ac\fhsalzburg\datakmu\service\DataPreProcessor.java:[3]
        public class DataPreProcessor {
                     ^^^^^^^^^^^^^^^^
Implicit super constructor Object() is undefined for default constructor. Must define an explicit constructor
[ERROR] C:\Users\its\git\datakmu\service-stack\stream-data-preprocessor\src\main\java\at\ac\fhsalzburg\datakmu\service\DataPreProcessor.java:[4]
        public static void main(String[] args) {
                                ^^^^^^
String cannot be resolved to a type

表示找不到基本的 SDK 类,例如“无法解析类型 java.lang.Object”。我正在与其他几个 Maven 项目合作,它们工作正常。我不明白,这一定是一些愚蠢的错误。

在这里你可以找到 pom.xml 文件:

<!--
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
-->

<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>stream-data-preprocessor</groupId>
    <artifactId>stream-data-preprocessor</artifactId>
    <version>0.1</version>
    <packaging>jar</packaging>

    <name>Kafka Streams Quickstart :: Java</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <slf4j.version>1.7.7</slf4j.version>
        <log4j.version>1.2.17</log4j.version>
        <java.version>8</java.version>
        <avro.version>1.9.1</avro.version>
        <gson.version>2.2.4</gson.version>
        <kafka.version>2.5.0</kafka.version>
        <confluent.version>5.5.1</confluent.version>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <repositories>
        <repository>
            <id>apache.snapshots</id>
            <name>Apache Development Snapshot Repository</name>
            <url>https://repository.apache.org/content/repositories/snapshots/</url>
            <releases>
                <enabled>false</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>confluent</id>
            <name>Confluent</name>
            <url>https://packages.confluent.io/maven/</url>
        </repository>
    </repositories>

    <!--
        Execute "mvn clean package -Pbuild-jar"
        to build a jar file out of this project!
    -->

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>${maven.compiler.source}</source>
                    <target>${maven.compiler.target}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.avro</groupId>
                <artifactId>avro-maven-plugin</artifactId>
                <version>${avro.version}</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>schema</goal>
                        </goals>
                        <configuration>
                            <sourceDirectory>${project.basedir}/src/main/resources/avro/</sourceDirectory>
                            <includes>
                                <include>SensorValue.avsc</include>
                            </includes>
                            <outputDirectory>${project.build.directory}/generated-sources</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>io.confluent</groupId>
                <artifactId>kafka-schema-registry-maven-plugin</artifactId>
                <version>${confluent.version}</version>
                <configuration>
                    <schemaRegistryUrls>
                        <param>http://localhost:28081</param>
                    </schemaRegistryUrls>
                    <subjects>
                        <transactions-value>src/main/resources/avro/Sentence.avsc</transactions-value>
                    </subjects>
                    <outputDirectory/>
                </configuration>
                <goals>
                    <goal>test-compatibility</goal>
                </goals>
            </plugin>
        </plugins>

        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>${maven.compiler.source}</source>
                        <target>${maven.compiler.target}</target>
                        <compilerId>jdt</compilerId>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>org.eclipse.tycho</groupId>
                            <artifactId>tycho-compiler-jdt</artifactId>
                            <version>0.21.0</version>
                        </dependency>
                    </dependencies>
                </plugin>
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>org.apache.maven.plugins</groupId>
                                        <artifactId>maven-assembly-plugin</artifactId>
                                        <versionRange>[2.4,)</versionRange>
                                        <goals>
                                            <goal>single</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore/>
                                    </action>
                                </pluginExecution>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>org.apache.maven.plugins</groupId>
                                        <artifactId>maven-compiler-plugin</artifactId>
                                        <versionRange>[3.1,)</versionRange>
                                        <goals>
                                            <goal>testCompile</goal>
                                            <goal>compile</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore/>
                                    </action>
                                </pluginExecution>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <dependencies>
        <!-- Apache Kafka dependencies -->
        <dependency>
            <groupId>org.apache.kafka</groupId>
            <artifactId>kafka-streams</artifactId>
            <version>${kafka.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.kafka</groupId>
            <artifactId>kafka-clients</artifactId>
            <version>${kafka.version}</version>
        </dependency>
        <!-- Dependencies below are required/recommended only when using Apache Avro. -->
        <dependency>
            <groupId>io.confluent</groupId>
            <artifactId>kafka-avro-serializer</artifactId>
            <version>${confluent.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.avro</groupId>
            <artifactId>avro</artifactId>
            <version>${avro.version}</version>
        </dependency>
    </dependencies>
</project>

据我所知,maven 也配置正确:

Maven home: C:\Users\its\scoop\apps\maven\current
Java version: 11.0.2, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-11.0.2
Default locale: de_AT, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

为了完整起见,主要的 java 类。我从原型中删除了所有其他代码 sn-ps:

package at.ac.fhsalzburg.datakmu.service;

public class DataPreProcessor {
    public static void main(String[] args) {
        //TODO
    }
}

有人可以帮忙吗?如果您需要任何进一步的输入,请告诉我! 谢谢

【问题讨论】:

  • 可以分享一下DataPreProcessor吗?
  • 我已经添加了它,但我怀疑它是否有帮助。真的就是这么简单。

标签: java maven apache-kafka apache-kafka-streams


【解决方案1】:

在您的 pom.xml 中,您有以下 sn-p。在 src/main/resources 中创建 avro 文件夹或删除 avro 部分。然后进行 mvn clean verify 以确保您的项目构建

       <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>schema</goal>
                    </goals>
                    <configuration>
                        <sourceDirectory>${project.basedir}/src/main/resources/avro/</sourceDirectory>
                        <includes>
                            <include>SensorValue.avsc</include>
                        </includes>
                        <outputDirectory>${project.build.directory}/generated-sources</outputDirectory>
                    </configuration>
                </execution>

【讨论】:

  • 谢谢雅各布,但是,文件夹在那里,因为我最终需要一些 avro 模式。尽管如此,我尝试删除该部分,但 mvn package 仍然给我同样的错误。
  • 我认为这与您的 intellij 配置有关。转到项目结构-> 项目-> 项目 sdk :确保在有效路径上将其设置为 1。项目结构相同-> sdks-> 右侧应该有 sdk 主路径。确保它设置正确,如果是这种情况,您将看到一堆库文件。你的 jdk。
  • 谢谢,仍然感谢您的努力,但我需要它才能使用命令行工具 mvn 编译它。所以我需要正确处理 pom.xml。
  • 我成功构建的 pom.xml 没有问题。
  • 可能需要设置一些环境变量,比如JAVA_HOME? javatutorial.net/set-java-home-windows-10
猜你喜欢
  • 2021-07-23
  • 2014-08-07
  • 2021-06-25
  • 2016-10-27
  • 2021-06-30
  • 2015-01-07
  • 2011-03-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多