Executing a batch file error: "Could not find or load the main class"

I am new to Java programming. I have a batch file called StartSample.bat. This batch file launches a java program. This is the code for the batch file:

@echo off
set CLASSPATH=%CLASSPATH%;f3bc4jav.jar
set CLASSPATH=%CLASSPATH%;PalmSecureSample_Java.jar

@echo on
java <classname>

The .jar files mentioned above are located in the same folder as the batch file.

When I run StartSample.bat, it runs the Java Program in the same way as it should.

Now, what I did, I created a Java Class to run this batch file using this code:

Process p = Runtime.getRuntime().exec("C:\\WINDOWS\\system32\\cmd.exe /c start C:\\Identify\\dll\\StartSample.bat");

Error starting my code. Error:

C:workspace\Project>java <classname> Error: Could not find or load main class <classname>

What is the problem?

+4
source share
2 answers

Java-, java.

, % ~ dp0:

@echo off
set CLASSPATH=%CLASSPATH%;%~dp0\f3bc4jav.jar
set CLASSPATH=%CLASSPATH%;%~dp0\PalmSecureSample_Java.jar

@echo on
java <classname>
+2

,

@echo off
set CLASSPATH=%CLASSPATH%;f3bc4jav.jar
set CLASSPATH=%CLASSPATH%;PalmSecureSample_Java.jar

@echo on
java -cp %CLASSPATH% com.xyz.path.to.MainClass.class
0

Source: https://habr.com/ru/post/1656951/


All Articles