生成的Maven项目具有编译器错误:“;”预期

时间:2019-01-21 09:15:20

标签: java maven-3

我正在使用改编的pom.xml建立一个新的maven java项目。编译器在生成的Maven Java应用程序上给出错误。为什么这样?

我将pom.xml修改为使用Java 1.8和Java 11进行编译,两者均无法正常工作。 Pom.xml适用于Fatjar的泛型,当删除每个Java代码时,它即可工作。 Pom.xml适用于junit 4.11。

<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>org.no-ip.leder.gmr</groupId>
<artifactId>gmr_mvn</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>gmr_mvn</name>
<url>http://maven.apache.org</url>

<properties>
    <jdk.version>11</jdk.version>
    <jodatime.version>2.5</jodatime.version>
    <junit.version>4.11</junit.version>
</properties>
<dependencies>
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>${junit.version}</version>
  <scope>test</scope>
</dependency>
</dependencies>
<build>
    <finalName>gmr-digital-signature-mvn</finalName>
    <plugins>



        <!-- Set a compiler level -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>${jdk.version}</source>
                <target>${jdk.version}</target>
            </configuration>
        </plugin>

        <!-- Maven Assembly Plugin -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4.1</version>
            <configuration>
                <!-- get all project dependencies -->
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <!-- MainClass in mainfest make a executable jar -->
                <archive>
                  <manifest>
                    <mainClass>org.no-ip.leder.gmr.Start</mainClass>
                  </manifest>
                </archive>

            </configuration>
            <executions>
              <execution>
                <id>make-assembly</id>
                                    <!-- bind to the packaging phase -->
                <phase>package</phase> 
                <goals>
                    <goal>single</goal>
                </goals>
              </execution>
            </executions>
        </plugin>

    </plugins>
</build>


</project>

预期:来自maven框架的App.java中的Hello world已编译或任何其他Java源。 实际:error: ';' expected

package org.no-ip.leder.test;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
    }
}

即使是未经修改的pom.xml(具有源1.6和目标1.6)也会出现错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project test_mvn: Compilation failure
[ERROR] /home/leder/Git/test_mvn/src/main/java/org/no-ip/leder/test/App.java:[1,15] ';' expected


<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>org.no-ip.leder.test</groupId>
  <artifactId>test_mvn</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>test_mvn</name>
  <url>http://maven.apache.org</url>
  <properties>
    <maven.compiler.source>1.6</maven.compiler.source>
    <maven.compiler.target>1.6</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

1 个答案:

答案 0 :(得分:5)

该错误是由于软件包名称org.no-ip.leder.test引起的; 减号是一个运算符,将其转换为下划线并相应地重命名文件夹。