Not able to run batch script to run "javadoc" on all classes at once

Phillip Powell 1 Reputation point
2022-10-04T22:28:14.033+00:00

I wrote a Windows Batch Script file that I thought would run "javadoc" on all of my Java classes at once. It prompts you to enter the root directory where the classes will be, then, once you do that, it will prompt you to enter a package name.

Once both values are entered (the first one will default to the Java Classpath if you don't enter anything), then it will load of all my jar files in /jar into a string, %_fileList%, which then should be imported into the -classpath parameter of the command. All of this takes place, and all of the classes in /jar work just fine.

Problem is that the jar files in /jar/spring are included into %_fileList% but are never referenced by "javadoc", and I can't figure out why.

Can someone please help? Here is the code:

:: If you want to use the Web CMA path, use C:\Users\phil\web_sandbox_062020\dandylabs\src  
:: Otherwise, it will default to the Java classpath to generate all javadocs  
  
@echo off  
SETLOCAL EnableDelayedExpansion  
SETLOCAL ENABLEEXTENSIONS  
set myPath="%JAVA_CLASS_PATH%"  
set /P myPath="Enter path (hit ENTER for default Java classpath [%JAVA_CLASS_PATH%]): "  
set /P packageName="Enter package name: "  
set packageName=%packageName:&=%  
cd "%myPath%"  
set xclassPaths=".;../jar/spring/spring*.jar;../jar/javax.json-1.1.jar;../jar/mail-1.5.0-b01.jar;../jar/activation-1.1.jar;../jar/image4j-0.7.2.jar"  
  
set _filelist=.  
  
::if /I %%f:~-3 == "jar"   
  
for /f "delims=|" %%f in ('dir /B C:\users\phill\OneDrive\Desktop\jar') do (  
  if exist ..\jar\%%f\* echo "..\jar\%%f is a directory"  
  if not exist %%f\* (set _filelist=!_fileList!;../jar/%%f)  
)  
  
for /f "delims=|" %%f in ('dir /B C:\users\phil\OneDrive\Desktop\jar\spring') do (  
  if not exist %%f\* (set _filelist=!_fileList!;../jar/spring/%%f)  
)  
  
set _filelist=%_filelist:,,=%  
  
::echo %_fileList%  
  
"%JAVA_JDK_HOME%\javadoc" -Xdoclint:none -classpath %_fileList% %packageName% && (  
	(call )  
) || (  
	PAUSE  
)  
Windows for business Windows Server User experience PowerShell
{count} votes

1 answer

Sort by: Most helpful
  1. Phillip Powell 1 Reputation point
    2022-10-05T05:01:58.643+00:00

    I figured it out; it was a very simple directory issue in the script. Once I made the directory values absolute, "javadoc" was able to find the required jar files to build into the -classpath parameter, and everything worked just fine

    I do need to eventually learn PowerShell, as Batch Script is crazy to work with

    :: If you want to use the Web CMA path, use C:\Users\phil\web_sandbox_062020\dandylabs\src  
    :: Otherwise, it will default to the Java classpath to generate all javadocs  
      
    @echo off  
    SETLOCAL EnableDelayedExpansion  
    SETLOCAL ENABLEEXTENSIONS  
    set myPath="%JAVA_CLASS_PATH%"  
    set jarBasePath=C:\Users\phil\OneDrive\Desktop  
    set /P myPath="Enter path (hit ENTER for default Java classpath [%JAVA_CLASS_PATH%]): "  
    set /P packageName="Enter package name: "  
    set packageName=%packageName:&=%  
    cd "%myPath%"  
      
    set _filelist=.  
      
    for /f "delims=|" %%f in ('dir /B %jarBasePath%\jar') do (  
      ::if exist %jarBasePath%\jar\%%f\* echo "%jarBasePath%\jar\%%f is a directory"  
      if not exist %jarBasePath%\jar\%%f\* (set _filelist=!_fileList!;%jarBasePath%\jar\%%f)  
    )  
      
    for /f "delims=|" %%f in ('dir /B %jarBasePath%\jar\spring') do (  
       ::if exist %jarBasePath%\jar\spring\%%f\* echo "%jarBasePath%\jar\spring\%%f is a directory"  
       if not exist %jarBasePath%\jar\spring\%%f\* (set _filelist=!_fileList!;%jarBasePath%\jar\spring\%%f)  
    )  
      
    set _filelist=%_filelist:,,=%  
      
    ::echo %_fileList%  
      
    "%JAVA_JDK_HOME%\javadoc" -Xdoclint:none -classpath %_fileList% %packageName% && (  
    	(call )  
    ) || (  
    	PAUSE  
    )  
      
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.