0
for /f "tokens=* delims= " %%a in (plugins.txt) do (
echo %%a
java -cp .;svnkit.jar Test %%a

cd %dotcms_home%

call ant deploy-plugins > test1.txt

FindStr "BUILD SUCCESSFUL" test1.txt

del "test1.txt"

cd C:\dotCMSResults
echo Errorlevel: %ERRORLEVEL%
if %ERRORLEVEL% ==1 (echo ^<tr BGCOLOR=\"#FF0000\"^>^<td^>Build^</td^>^<td^>Fout\!^</td^>^</tr^> >> goedje.html ) else (echo ^<tr BGCOLOR=\"#00FF00\"^>^<td^>Build^</td^>^<td^>Gelukt\!^</td^>^</tr^> >> goedje.html) 
cd %dotcms_home%
call ant undeploy-plugins > test.txt
)

Hello, I want to run a Java class in commandline in a while loop. I searched on Google and found a way to do it. But now he is only doing it the first time, the second and third time he said:

Exception in thread "main" java.lang.NoClassDefFoundError: Test
Caused by: java.lang.ClassNotFoundException: Test
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: Test.  Program will exit.

I don't know why, esspecialy because he is running the first time correct. Only the second and third time he is going in the loop he gets this error.

1 Answer 1

4

This is most probably due to your cd statements - you must be changing away from the current directory which contains the svnkit.jar (or a Test.class?) so that it can't find Test class anymore on the second loop.

To fix that add cd to the correct directory before calling java.

Or, which is better, use absolute paths as a java classpath argument, i.e.

java -cp c:/folder1;c:/folder2/svnkit.jar.

Sign up to request clarification or add additional context in comments.

3 Comments

Agreed, this is the most likely cause. The error you're getting simply means that the JVM can't find the Test class you specified when starting the JVM.
Hmm.. This still not works, but I think I did something wrong: java -cp .;"C:\dotCMS Automatic Install\svnkit.jar" "C:\dotCMS Automatic Install\Test" %%a
@Gynnad instead of "C:\dotCMS Automatic Install\Test" just put Test

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.