I created a Maven quickstart project using the "Maven: Getting Started" instructions. This is the command I ran to create the project: mvn archetype:generate -DgroupId=org.development.package -DartifactId=maven_package_example -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.0 -DinteractiveMode=false
. I put in underscores in the package name as suggested by this other StackOverflow post. I ran mvn compile
and get a compilation failure error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.13.0:compile (default-compile) on project maven_package_example: Compilation failure
[ERROR] /Users/mdailey/maven_package_example/src/main/java/org/development/package/App.java:[1,22] <identifier> expected
My App.java
file looks like this:
package org.development.package;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}
I don't have much experience using Maven. Is the code Maven is generating not correct? Or is the Java I have installed on my computer which is 23.0.2 not compatible with this Maven quickstart project? I've tried changing the name field in the pom.xml by removing all underscores but still get the same error. I can't figure out what is the problem. Any help would be appreciated.
This has nothing to do with Maven (other than that Maven is generating code without validating its input). Compile the same code with javac
and you'll get the same error.
The problem is your use of package
in your package name of org.development.package
. That's invalid because package
is a keyword.
A package declaration is basically a dot-separated sequence of identifiers, and an identifier is not allowed to be a keyword.