Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch Create Java Class Stubs

Given a list of potential class names: 1. Alaska . . . 50. Wyoming

Is there a tool that will create empty java class files for each with supplied parameters? I'm thinking of something like the "New...Class" dialog in Eclipse, only on steriods. :-)

Thanks in advance, Kyle

like image 347
PurpleAce1979 Avatar asked Feb 05 '26 16:02

PurpleAce1979


1 Answers

I am not sure if a batch new class wizard exists, but it would take as long to find one as it would to roll your own in a simple bat. I would use a for loop, iterating over the contents of a file that lists the Class names to be created, and in the body of the loop echo the template to the newly created file, using the value from the file to both name the .java as well as to fill in the classname in the template.

EDIT: an example bat which reads class names from a file called classnames.txt and creates very simple stubs:

for /F "tokens=1" %%a in (classnames.txt) do call :createClass %%a

dir *.java

goto :eof

:createClass 
   echo package com.abc; > %1.java 
   echo.  >> %1.java 
   echo public class %1 {>> %1.java 
   echo      public %1() { >> %1.java 
   echo      } >> %1.java 
   echo } >> %1.java
like image 81
akf Avatar answered Feb 08 '26 06:02

akf