[英]Java command line compile
I recently finished a programming assignment using Netbeans and Java. 我最近完成了使用Netbeans和Java的编程任务。 When I run the program in Netbeans everything runs perfect.
当我在Netbeans中运行该程序时,一切运行正常。 My issue comes when I try and run it from the terminal.
当我尝试从终端运行它时,我的问题就来了。 I run javac with all my .java files and it produces a .class file for each one.
我用所有的.java文件运行javac,并且为每个文件生成一个.class文件。 Then when I try to run the executable it errors out on me.
然后,当我尝试运行可执行文件时,我就出错了。
ls
Board.java KenKenPuzzleSolver.java
Solver.java Cage.java
Size.java Values.java
javac KenKenPuzzleSolver.java Board.java Cage.java Size.java Solver.java Values.java
ls
Board.class Size.class
Board.java Size.java
Cage.class Solver.class
Cage.java Solver.java
KenKenPuzzleSolver.class Values.class
KenKenPuzzleSolver.java Values.java
java KenKenPuzzleSolver
Exception in thread "main" java.lang.NoClassDefFoundError: KenKenPuzzleSolver (wrong name: kenkenpuzzlesolver/KenKenPuzzleSolver)
Also, when the program is run from the terminal it should take in an input file and the name of an output file ie "java KenKenPuzzleSolver input.txt output.txt", and I am not quite sure how to do this. 另外,从终端运行程序时,它应该输入一个输入文件和一个输出文件的名称,即“ java KenKenPuzzleSolver input.txt output.txt”,我不太确定该怎么做。
Why don't you generate an executable with netbeans? 为什么不使用netbeans生成可执行文件? You don't have to compile your code every time.
您不必每次都编译代码。
input.txt
and output.txt
are called arguments. input.txt
和output.txt
称为参数。 They will be stored in the String[] args
array in you main
function. 它们将存储在
main
函数中的String[] args
数组中。
You did not provide the classpath parameter. 您未提供classpath参数。
Use javac -cp YOURCLASSPATH KenKenPuzzleSolver
使用
javac -cp YOURCLASSPATH KenKenPuzzleSolver
The class that you are running should be public and should have the class name same as your file name. 您正在运行的类应为公共类,并且其类名应与文件名相同。 It seems like your file name is "KenKenPuzzleSolver" but your class name seems to be "KenkenPuzzleSolver" ( Observe the lowercase ken ).
您的文件名似乎是“ KenKenPuzzleSolver”,但您的类名似乎是“ KenkenPuzzleSolver”(请注意小写ken)。 correct that and recompile and re run.
更正该错误,然后重新编译并重新运行。
您一定已经搞砸了案例,因为错误已经很明显了,而不是在KenKenPuzzleSolver
类命名为kenkenpuzzlesolver
,而不是KenKenPuzzleSolver.java
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.