XMLbeans scomp fails with “java.io.IOException: CreateProcess error=2, The system cannot find the file specified”

Beans Alubia pinta alavesa. Álava, Spain.
Image via Wikipedia

If you are using xmlbeans on Windows to bind your schema to Java types then you are probably using a tool bundled with the distribution called scomp or Schema Compiler. For schema compiler to work you will need to correctly setup computer environment by installing JDK. You can follow through the following check-list to detect if any additional installation steps are required on your machine setup:

  • Start->Run->type cmd and type java in the command line. If no error then your setup is correct; otherwise setup JAVA_HOME and add %JAVA_HOME%/bin to your Path environment variable and try again.
  • Start->Run->type cmd and type scomp in the command line. If no error then your setup is correct; otherwise setup XMLBEANS_HOME and add %XMLBEANS_HOME%/bin to your Path environment variable and try again.

Then run scomp. Depending on your wishes you will probably wan’t to create a .jar file of the Java types scomp compiles from schema files. I used the following command line:

scomp -d schema -src src -out my_schema_1_0_0.jar ./schema/mySchema.xsd

where mySchema.xsd file was stored in ./schema folder.

If you get my_schema_1_0_0.jar, by some coincidence then kudos to you, but most likely you will end up with something similar to this error:

Time to build schema type system: 1.282 seconds
Time to generate code: 18.687 seconds
java.io.IOException: Cannot run program "C:\your current path\javac": CreateProcess error=2, The system cannot find the file specified
java.io.IOException: CreateProcess error=2, The system cannot find the file specified
java.io.IOException: Cannot run program "C:\your current path\javac": CreateProcess error=2, The system cannot find the file specified
 at java.lang.ProcessBuilder.start(Unknown Source)
 at java.lang.Runtime.exec(Unknown Source)
 at java.lang.Runtime.exec(Unknown Source)
 ... 6 more
BUILD FAILED

Read on to solve this problem.

Yay!!!  There is a problem in your Path environment variable. Let’s try to troubleshoot. Did you install JDK? If you did not then install it. If you did you probably installed it by accepting default installation values. It was installed to C:\Program files\Java\jdk<version>.

The problem is “Program files”. See the space? Java does not like spaces in the command line. As in any other programming language, space represents additional argument to the program. You could try to replace the C:\Program files with classical 8.3 old MS-DOS format, which 1980 users love so much. Execute dir /x in C:\ and replace your “Program files” with PROGRA~2 or PROGRA~1 or whatever Windows thinks “Program files” maps to in your JAVA_HOME and Path environment variables. I am guessing that this will not win me a gold star and you are still reading the next paragraph. And I promise you that if you click one of the Support Us links on the right side you will have three less starving wise men in the world1, and you will feel content with your self by clicking on it2. But your Path environment variables are now setup correctly.

Now you could search the web and find the answer. Use 2’5 hours of your precious time and crack this. Or you could read documentation for scomp. By being smart and reading documentation for scomp you will discover that scomp can solve this Windows nightmare for you. By using the -compiler parameter in command line you get something like this:

scomp -d schema -src src -out my_schema_1_0_0.jar ./schema/mySchema.xsd -compiler C:\Program Files\Java\jdk1.6.0_03\bin\javac.exe

Problem solved.

Note: If you have huge .xsd schemas then you will have to boost memory external Java compiler can use. Use -xm 512m or -xm 1024m to successfully compile your schema.

Reblog this post [with Zemanta]


Footnotes:
  1. not really, but maybe we will get that dinner at some time []
  2. really click on the support us button on the right and try it out []


Leave a comment