How can I compile and run a Java class in a different directory?

后端 未结 3 1692
孤独总比滥情好
孤独总比滥情好 2020-12-01 06:20

I\'m writing a makefile that compiles a .java file in a different directory, and then I want to run it, without changing directories. I want to do something alo

3条回答
  •  星月不相逢
    2020-12-01 07:06

    Use the -d command line parameter with javac to tell it what directory you'd like to store the compiled class files in. Then, to run the program, simply include this directory in the classpath:

    javac -d some/directory myjavafile.java
    java -cp some/directory myjavafile
    

提交回复
热议问题