无法编译Maven项目。

huangapple 未分类评论69阅读模式
英文:

Cannot compile maven project

问题

我使用了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类无法找到,比如 "The type java.lang.Object cannot be resolved"。我正在处理其他几个Maven项目,它们都正常工作。我不明白,一定是某个愚蠢的错误。

这里是 pom.xml 文件:

<!-- 这里是您的 pom.xml 内容 -->

另外,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 类。我从原型中删除了所有其他代码片段:

package at.ac.fhsalzburg.datakmu.service;

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

有人可以提供帮助吗?如果您需要进一步的信息,请随时告诉我!谢谢。

英文:

I started a simple project using an artefact from confluent. But when I try to compile the project using mvn clean install or mvn clean package I am getting message like

[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

indicating that basic SDK classes are not found like "The type java.lang.Object cannot be resolved". I am working with several other Maven project and they work fine. I do not get it, it must be really some stupid error.

Here you can find the pom.xml file:

&lt;!--
   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 &quot;License&quot;); 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 &quot;AS IS&quot; 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.
--&gt;

&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
         xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
         xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;

    &lt;groupId&gt;stream-data-preprocessor&lt;/groupId&gt;
    &lt;artifactId&gt;stream-data-preprocessor&lt;/artifactId&gt;
    &lt;version&gt;0.1&lt;/version&gt;
    &lt;packaging&gt;jar&lt;/packaging&gt;

    &lt;name&gt;Kafka Streams Quickstart :: Java&lt;/name&gt;

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

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

    &lt;!--
		Execute &quot;mvn clean package -Pbuild-jar&quot;
		to build a jar file out of this project!
	--&gt;

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

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

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

Also maven is configured correctly, as far as I can see:

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: &quot;windows 10&quot;, version: &quot;10.0&quot;, arch: &quot;amd64&quot;, family: &quot;windows&quot;

For completeness the main java class. I deleted all other code snippets from the archetype:

package at.ac.fhsalzburg.datakmu.service;

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

Could someone help? If you need any further input just let me know!
Thx

答案1

得分: 0

在您的 pom.xml 文件中,您有以下片段。要么在 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>
英文:

In your pom.xml you have the following snippet. Either create the avro folder in src/main/resources or remove the avro part. Then do a mvn clean verify to make sure your project builds

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

huangapple
  • 本文由 发表于 2020年8月14日 23:13:53
  • 转载请务必保留本文链接:https://java.coder-hub.com/63415462.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定