[英]Java Could not find main class Error after running by Notepad++
I have been running java by Command Prompt
in Win 7 Ultimate using only filename (Ex. javac program.java
and java program) before running java by Notepad++ script. 在通过Notepad ++脚本运行Java之前,我一直在Win 7 Ultimate中通过
Command Prompt
运行Java,仅使用文件名(例如, javac program.java
和Java程序)运行。
After using Notepad++ script and update Java to version jdk-8u77-windows-i586
I could only able to run java by Notepad++ only. 使用Notepad ++脚本并将Java更新到版本
jdk-8u77-windows-i586
我只能通过Notepad ++运行Java。 I get 我懂了
Error: Could not find or load main class CopyFile
错误:找不到或加载主类CopyFile
when I run it in Command prompt. 当我在命令提示符下运行它时。 But I can use 'javac' in command line to compile the java program.
但是我可以在命令行中使用“ javac”来编译java程序。
Below is my Notepad++ script that runs java program inside of it. 以下是我的Notepad ++脚本,该脚本在其中运行Java程序。
NPP_SAVE
cd "$(CURRENT_DIRECTORY)"
"C:\Program Files (x86)\Java\jdk1.8.0_77\bin\javac" $(FILE_NAME)
"C:\Program Files (x86)\Java\jdk1.8.0_77\bin\java" -classpath "$(CURRENT_DIRECTORY)" "$(NAME_PART)"
I have checked environment variables and all of them are set. 我已经检查了环境变量,并且都设置了。 I've given them below.
我在下面给了他们。
CLASSPATH 类路径
C:\Program Files (x86)\Java\jdk1.8.0_77\bin;C:\Program Files (x86)\Java\jre1.8.0_77\bin
JAVA_HOME JAVA_HOME
C:\Program Files (x86)\Java\jdk1.8.0_77
Path 路径
C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Java\jdk1.8.0_77\bin;C:\Program Files (x86)\Java\apache-maven-3.3.9\bin;C:\xampp\ImageMagick-6.9.1-Q16;C:\Python27\;C:\Python27\Scripts;C:\Python27\DLLs;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;D:\Dhay\Tasks by me\Firefox addon job\addon-sdk-1.17\bin;C:\Program Files\MySQL\MySQL Server 5.1\bin;C:\Program Files\Google\Cloud SDK\google-cloud-sdk\bin;C:\Program Files (x86)\Common Files\lenovo\easyplussdk\bin;C:\Program Files (x86)\QuickTime\QTSystem\
Below is the java file. 以下是java文件。
import java.io.*;
class CopyFile
{
public static void main (String args[]) throws IOException
{
int i;
FileInputStream fin = null;
FileOutputStream fout = null;
if(args.length != 2)
{
System.out.println("Usage: CopyFile from to");;
return;
}
try
{
fin = new FileInputStream(args[0]);
fout = new FileOutputStream(args[1]);
do {
i = fin.read();
if(i != -1) fout.write(i);
} while(i != -1);
} catch(IOException e){
System.out.println("I/O Error: " + e);
} finally {
try
{
if(fin != null) fin.close();
} catch(IOException e2)
{
System.out.println("Error Closing Input file");
}
try
{
if(fout != null) fout.close();
} catch(IOException e2)
{
System.out.println("Error Closing Output File");
}
}
}
}
Even I could able to run it in command line just by 甚至我也可以在命令行中运行它
java -classpath . CopyFile
I am just curious what might be wrong. 我很好奇可能出了什么问题。
您的当前目录不在您的类路径中,因此java找不到您的类,然后您告诉java,通过以下方法进入当前目录以找到CopyFile:
java -classpath . CopyFile
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.