Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generated maven project has compiler error: ';' expected

Tags:

java

maven-3

I am setting up a new maven java project with adapted pom.xml. The compiler gives an error on the generated maven java app. Why so?

I adapted pom.xml for compilation with java 1.8 and java 11, both are not working. Pom.xml is adapted for genearation of fatjar, which works when every java code is removed. Pom.xml is adapted for 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>

Expected: Hello world in App.java from maven framework is compiled or any other java source. Actual: error: ';' expected

package org.no-ip.leder.test;

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

Even unmodified pom.xml, with source and target 1.6, gives the error:

[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>
like image 203
Leder Avatar asked Dec 14 '22 13:12

Leder


1 Answers

The error is due to the package name, package org.no-ip.leder.test; The minus sign is an operator, convert that to an underscore and rename your folder accordingly.

like image 135
David Kabii Avatar answered Dec 24 '22 11:12

David Kabii