0

Seeing compilation error in maven. Checked and tried all the workarounds which i got from google and stack* sites. but still i couldnt resolve.

Installed maven 3.3.3 and its supported version of java which is 1.7. Please note i haven't set JAVA_HOME, M2 and M2_HOME environment variables. but still takes the path.

Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T07:57:37-04:00)
Maven home: /usr/local/apache-maven-3.3.3
Java version: 1.7.0_85, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.85.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "2.6.32-573.3.1.el6.x86_64", arch: "amd64", family: "unix"

Errors are

[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/sdiuser/Build-Release/hg-artifactid/src/main/java/hg-groupid/App.java:[1,11] ';' expected
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.007 s
[INFO] Finished at: 2015-08-31T02:43:32-04:00
[INFO] Final Memory: 9M/158M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project hg-artifactid: Compilation failure
[ERROR] /home/sdiuser/Build-Release/hg-artifactid/src/main/java/hg-groupid/App.java:[1,11] ';' expected
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project hg-artifactid: Compilation failure
/home/sdiuser/Build-Release/hg-artifactid/src/main/java/hg-groupid/App.java:[1,11] ';' expected

    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
/home/sdiuser/Build-Release/hg-artifactid/src/main/java/hg-groupid/App.java:[1,11] ';' expected

    at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:858)
    at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:129)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    ... 20 more
divakar.scm
  • 1,256
  • 5
  • 21
  • 32
  • 1
    Is line 1 of App.java terminated with a `;`? – Tobb Aug 31 '15 at 06:51
  • yes. package hg-groupid; /** * Hello world! * */ public class App { public static void main( String[] args ) { System.out.println( "Hello World!" ); } } – divakar.scm Aug 31 '15 at 06:59

1 Answers1

5

Going out on a limb here... but does line 1 of App.java contain the following package definition:

package hg-groupid;

If so, the problem relates to the hyphen you have in the package name - Java identifiers are not permitted to contain a hyphen in their name - you may wish to change this to an underscore.

See also: Hyphenated company name in Java packages

Community
  • 1
  • 1
Crollster
  • 2,751
  • 2
  • 23
  • 34
  • Thanks alot. Define value for property 'package': whether this is an issue? can you tell what is the property for? – divakar.scm Aug 31 '15 at 07:06
  • Not quite sure what you're asking... `package` is a reserved word in Java, so you shouldn't try to create a property named that. If you're asking what should the first line be - probably something like `package hg_groupid` (but you'll also need to change the name of the directory in which the App.java resides - to `hg_groupid`) – Crollster Aug 31 '15 at 07:09
  • Thanks, solved my problem. Created my package through the interactive prompt using mvn archetype:generate. Guess it wouldn't be too difficult to prevent the user from specifying package names with hyphens there... (it didn't complain at all there) – Igor Jul 19 '17 at 09:43