XMLBean scomp (schema compiler) fails with java.io.IOException: Cannot run program “..\xmlbeans-2.5.0 \bin\javac”: CreateProcess error=2, The system cannot find the file specified

I tried to generate JAR file from XSD file, but I end up with the below error
E:\J2EE\Apache_XML_Beans\xmlbeans-2.5.0\bin>scomp -out tutorials\gettingstarted\
lib\easypo.jar schemas\easypo\easypo.xsd
Time to build schema type system: 0.531 seconds
Time to generate code: 0.094 seconds
java.io.IOException: Cannot run program “E:\J2EE\Apache_XML_Beans\xmlbeans-2.5.0
\bin\javac”: CreateProcess error=2, The system cannot find the file specified
java.io.IOException: CreateProcess error=2, The system cannot find the file spec
ified
java.io.IOException: Cannot run program “E:\J2EE\Apache_XML_Beans\xmlbeans-2.5.0
\bin\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)
at org.apache.xmlbeans.impl.tool.CodeGenUtil.externalCompile(CodeGenUtil
.java:231)
at org.apache.xmlbeans.impl.tool.SchemaCompiler.compile(SchemaCompiler.j
ava:1154)
at org.apache.xmlbeans.impl.tool.SchemaCompiler.main(SchemaCompiler.java
:373)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find th
e file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
… 6 more
BUILD FAILED

If you are facing the same problem, try the following options

First, be sure you have a JDK installed. The JRE doesn’t have the javac program so you won’t be able to compile the generated java source. If you have both a JDK and a JRE installed, the JRE’s java is being found before the JDK’s java. Since scomp uses the ‘java.home’ property to find the javac program, but javac is only available in the JDK, finding javac will fail. Move the JDK higher up on the PATH in the environment.

If that doesn’t fix the issue, try specifying relevant paths using Windows 8.3 names. This will get around issues with spaces in folder names. For example, 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.

Documentation for scomp you will discover that scomp can solve this by using the -compiler parameter in command line you get something like this:

Try using the -compiler parameter,

 

E:\J2EE\Apache_XML_Beans\xmlbeans-2.5.0\bin>scomp -out tutorials\gettingstarted\
lib\easypo.jar schemas\easypo\easypo.xsd -compiler
Time to build schema type system: 0.547 seconds
Time to generate code: 0.094 seconds
java.io.IOException: Cannot run program “E:\J2EE\Apache_XML_Beans\xmlbeans-2.5.0
\bin”: CreateProcess error=5, Access is denied
java.io.IOException: CreateProcess error=5, Access is denied
java.io.IOException: Cannot run program “E:\J2EE\Apache_XML_Beans\xmlbeans-2.5.0
\bin”: CreateProcess error=5, Access is denied
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at org.apache.xmlbeans.impl.tool.CodeGenUtil.externalCompile(CodeGenUtil
.java:231)
at org.apache.xmlbeans.impl.tool.SchemaCompiler.compile(SchemaCompiler.j
ava:1154)
at org.apache.xmlbeans.impl.tool.SchemaCompiler.main(SchemaCompiler.java
:373)
Caused by: java.io.IOException: CreateProcess error=5, Access is denied
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
… 6 more
BUILD FAILED
E:\J2EE\Apache_XML_Beans\xmlbeans-2.5.0\bin>

 

If that doesn’t fix the issue, try the following by giving complete path of Java compiler with -compiler parameter,


E:\J2EE\Apache_XML_Beans\xmlbeans-2.5.0\bin>scomp -out tutorials\gettingstarted\lib\easypo.jar schemas\easypo\easypo.xsd -compiler C:\PROGRA~1\Java\jdk1.6.0_12\bin\javac.exe

Time to build schema type system: 0.547 seconds

Time to generate code: 0.078 seconds

Time to compile code: 2.672 seconds

Compiled types to: tutorials\gettingstarted\lib\easypo.jar

E:\J2EE\Apache_XML_Beans\xmlbeans-2.5.0\bin>

Advertisements

2 Comments

  1. EA
    Posted August 16, 2013 at 7:44 am | Permalink | Reply

    Hi Saravanan!

    Thank you for your hints to fix this problem 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: