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.
After using Notepad++ script and update Java to version jdk-8u77-windows-i586 I could only able to run java by Notepad++ only. I get
Error: Could not find or load main class CopyFile
when I run it in Command prompt. But I can use 'javac' in command line to compile the java program.
Below is my Notepad++ script that runs java program inside of it.
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
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.
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.
Error: Could not find or load main class filename