Splitting large Axis generated files into separate classes
I recently had to struggle with a SOAP webservice class generated by Apache Axis2. The class file
was more than 13 MB in size, and contained more than 290.000 lines of code - much more than
Eclipse, IntelliJ IDEA or NetBeans could handle. After some rather unsuccessful attempts to work around
the problem, I finally decided to write a little tool to split the huge file into smaller pieces.
Apache Axis generates a stub class with all required parameter classes placed as nested classes within the stub class. Therefore I decided to extract each nested class into its own class file, turning it into a standard Java class. This additionally requires to rewrite all references to this class that use the stub class’s name.
Here’s the source. It’s also available on GitHub. It’s written in Scala, but should be easily transformable into any other language, since it just consists of a single method “main”.
To compile, place it a file, change the variables “in_dir”, “classname_prefix”, and “namespace”, and compile it using the Scala compiler or run it as a script. Here’s how to use the Scala compiler.
The code is more or less straight forward: Look for class declaration. When a class is found, copy stuff until the end of the class. The end of a class declaration is simply the next closing bracket, after a the comment stating the end of the factory class declaration. The Axis developers really should be thanked for this comment, since else it would be more complicated to determine the end of a class declaration. One should count curly brackets, I guess.