简体   繁体   中英

What am I doing wrong to get an "error: invalid flag"?

I keep getting a compiling "Error: Invalid Flag" when trying to compile test programs in Java.

C:\javafun>javac -d mod\jdojo.intro src\jdojo.intro\module-info.java src\jdojo.intro\com\jdojo\intro\Welcome.java;

I have checked the PATH settings under environment variables to make sure the correct directory is listed. These are test files from the textbook "Beginning Java 17 Fundamentals" written by Sharan & Davis.

I have tried this code on two different Windows 10 machines using the command prompt. I've used the same process for both and am very new to coding so any step could be done incorrectly. I wrote the programs in Notepad and saved them to the correct directory as a.java file.

I've even tried typing out the whole directory path for both file paths. Here are the two programs I'm trying to compile:

// module-info.java
module jdojo.intro {
// An empty module body
}

// Welcome.java
package com.jdojo.intro;
public class Welcome {
public static void main (String[] args) {
    System.out.println("Welcome to Java 17!");
    }
}

What am I doing wrong?

Creating an answer based on comment from @dave_thompson_085.

On Windows, the presence or absence of ; at the end of the command changes the behavior.

So instead of running this:

C:\javafun>javac [...]ome.java;

run this:

C:\javafun>javac [...]ome.java

The full working command is here:

C:\javafun>javac -d mod\jdojo.intro src\jdojo.intro\module-info.java src\jdojo.intro\com\jdojo\intro\Welcome.java

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM