简体   繁体   中英

How do i run an intellij Java project from command line?

In Intellij, when i run a java project (via CTRL+SHIFT+F10) on the class that has a public static void main method, the project runs as expected. Now, i want to run this same file/project, but on the command line. Furthermore, i want to be able to update this file and re-run it.

I copied the command that Intellij outputs into the console, and i stuck that command on the terminal. the command looks something like this:

/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/bin/java -Didea.launcher.port=7532 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA 14 CE.app/Con ...... (it's an insanely long command)

Let's say my file looks like this:

public class Main {
    public static void main(String...args){System.out.println("hi");}
}

==> outputs "hi" when i run the command.

While this command runs just fine on terminal, it does NOT pick up any updates to the file. if i save the file, the previous cached files are run.

ie let's say now i modify the file to be:

public class Main {
    public static void main(String...args){System.out.println("GOOD BYE");}
}

==> the output is still "hi". even if i save the file.

I'm running the command from home directory.

How do i get the command to pick up my changes?

If i run again from intellij with the updated file, it gives the same command as previously (well, other than the port changes).

========================================================================

Update:

okay, it looks like the command is running just a .class file. But i still can't see the commands used to build the .class file. how do i do this?

You need to rebuild the project before running it if you want to see your changes. You can use javac but I suggest you use a build tool like maven or gradle.

Once you have rebuilt your project you can run the latest build.

You can also create a script which first compiles your program before it runs it like IntelliJ does.

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