Skip to content

mvn compile OK, but mvn compile exec:java -D exec.mainClass=”mygroup.TestExpression” fails

I’ve refered to this post: Resource specification not allowed here for source level below 1.7

I used the solution, but didn’t solve problem.

Well I’m not using eclipse but jdk 1.8 + vscode on win10, using maven to generate a new project:

mvn archetype:generate

add these lines in my pom.xml inside the top level <project> tag:


Then I have this code:

public static void main(String[] args) {
        try(Scanner sc = new Scanner( { // Error!
            String infix;
            while(! (infix = sc.nextLine()).isEmpty()) {

Using mvn compile ok, but using mvn compile exec:java -D exec.mainClass="mygroup.TestExpression" will fail:

It reports error:

mvn compile exec:java -D exec.mainClass="mygroup.TestExpression"

[INFO] --- exec-maven-plugin:3.0.0:java (default-cli) @ myalgos ---
java.lang.Error: Unresolved compilation problem: 
        Resource specification not allowed here for source level below 1.7

    at mygroup.TestExpression.main (
    at org.codehaus.mojo.exec.ExecJavaMojo$ (
    at (
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------

You could see I’ve specified maven-compiler-plugin version 3.8.0, while command line output showed exec-maven-plugin:3.0.0:.

I’m not sure if this was the reason, what’s the difference between mvn compile and mvn compile exec:java -D exec.mainClass="mygroup.TestExpression"?

How to solve this problem(compile+run in one step)?




Try specifying java version in properties tag inside pom


Also check out this link, maybe you’ll find something new there

2 People found this is helpful