The
thing to keep in mind is that there may be multiple directories all of which are
named "Package1", but in different source tree roots.
For
instance, your project might have the following structure:
build/
build/classes/
build/generatedSrc/
build/generatedSrc/com/
build/generatedSrc/com/example/
build/generatedSrc/com/example/Package1
build/generatedSrc/com/example/Package1/MyClass.java
src/src/com/
src/com/example/
src/com/example/Package1
src/com/example/Package1/MyOtherClass.java
There
are two different source tree roots in the above structure: "build/generatedSrc"
and "src". If these are configured properly, then MyClass and MyOtherClass will
be considered to be in the same package.
Also
note that the entire 'build' directory doesn't need to be checked into version
control. It only contains transient data that is created or updated when a build
happens.
Now,
notice that there are TWO directories here named "Package1". If both
"build/generatedSrc" and "src" are named as root directories in your 'javac'
invocation, then these two directories will both be considered to be in the same
package, and any Java source files that are found in either of them will be
considered to be in the same package by javac, which will output only
one directory containing ".class" files constructed from the contents of
these two source directories.
Therefore, you can have WSDL2Java generate files into the generatedSrc
root, thus overwriting the contents of build/generatedSrc/com/example/Package1,
but leaving any files that you have in src/com/example/Package1
untouched.
If you
have an identically named file in both Package1 directories, you will have a
problem. Therefore, if you want to, for instance, customize your skeleton file,
you can move a generated file out of the generatedSrc tree into the src tree and
then modify it as you like. To prevent the file from being regenerated and
conflicting with your modified version (since they will have the same name and
package) you can make your ANT script or whatever runs WSDL2Java for you just
delete that file every time it is generated in the future, thus leaving your own
modified version as the only file with that name and
package.
For
instance, my WSDL2Java invocation looks something like this:
<property name="wsdl"
location="MyWSDL.wsdl"/>
<property name="generatedSrc" location="${build}/generatedSrc"/>
<property name="generatedSrc" location="${build}/generatedSrc"/>
<target
name="generateJava">
<!--These deletions are necessary because WSDL2Java refuses to overwrite these files if they are found -->
<delete dir="${generatedSrc}/com/example/Package1" includes="*.java" failonerror="false"/>
<!--These deletions are necessary because WSDL2Java refuses to overwrite these files if they are found -->
<delete dir="${generatedSrc}/com/example/Package1" includes="*.java" failonerror="false"/>
<!-- Consult http://ws.apache.org/axis2/tools/1_0/CodegenToolReference.html
for details on the following -->
<java classname="org.apache.axis2.wsdl.WSDL2Java" fork="true" failonerror="true">
<classpath refid="axis.classpath"/>
<arg value="--databinding-method"/>
<arg value="xmlbeans"/>
<arg value="--uri"/>
<arg value="${wsdl}"/>
<arg value="--server-side"/>
<arg value="--generate-all"/>
<arg value="--service-description"/>
<arg value="--output"/>
<arg value="${generatedSrc}"/>
<arg value="--package"/>
<arg value="com.example.Package1"/>
<arg value="--namespace2package"/>
<java classname="org.apache.axis2.wsdl.WSDL2Java" fork="true" failonerror="true">
<classpath refid="axis.classpath"/>
<arg value="--databinding-method"/>
<arg value="xmlbeans"/>
<arg value="--uri"/>
<arg value="${wsdl}"/>
<arg value="--server-side"/>
<arg value="--generate-all"/>
<arg value="--service-description"/>
<arg value="--output"/>
<arg value="${generatedSrc}"/>
<arg value="--package"/>
<arg value="com.example.Package1"/>
<arg value="--namespace2package"/>
<arg value=http://www.example.com/wsdl/2004-10-01=com.example.xmlbeans.wsdl/>
<arg value="--namespace2package"/>
<arg value="--namespace2package"/>
<arg
value="http://www.w3.org/2004/06/xmlmime=com.example.xmlbeans.xmlmime"/>
<arg value="--namespace2package"/>
<arg value="--namespace2package"/>
<arg
value="http://schemas.xmlsoap.org/soap/encoding/=com.example.xmlbeans.soapencoding"/>
</java>
</java>
<!-- Delete the
skeleton file that was generated, since there is a custom version in the 'src'
tree -->
<delete
dir="${generatedSrc}/src/com/example/Package1"
includes="*Skeleton.java"/>
</target>
My
invocation of javac is something like the following. Note that there are
TWO 'src' lines, indicating that there are two source roots:
<target name="compile"
depends="generateJava">
<path
id="axis.classpath">
<fileset dir="${lib}/axis2" includes="*.jar"/>
</path>
<javac source="1.5" destDir="${build}/classes" verbose="true" debug="true" failonerror="true">
<src location="${src}"/>
<src location="${generatedSrc}"/>
<classpath refid="axis.classpath"/>
<include name="**/*.java"/>
</javac>
<fileset dir="${lib}/axis2" includes="*.jar"/>
</path>
<javac source="1.5" destDir="${build}/classes" verbose="true" debug="true" failonerror="true">
<src location="${src}"/>
<src location="${generatedSrc}"/>
<classpath refid="axis.classpath"/>
<include name="**/*.java"/>
</javac>
</target>
I hope
this helps!
Derek
-----Original Message-----
From: Amit Andhale [mailto:[EMAIL PROTECTED]
Sent: Tuesday, August 01, 2006 2:53 AM
To: [email protected]; [EMAIL PROTECTED]
Subject: Re: Axis 1.3 WSDL2Java Overwrites the original filesHi Derek,Thanks for prompt reply.My Problem is that,In my Java Project, I have written some classes in packages e.g "Package1".My Web Service classes refer to these classes in "Package1".When I run WSDL2Java command, it generates the referred classes also in "Package1" overwriting the original classes, and generates Web Service stub in another specified package.I don't want WSDL2Java to overwrite Classes in "Package1" which would be used by other projects also.Is there any way to do this?Amit
On 7/31/06, Derek <[EMAIL PROTECTED]> wrote:What I do is have my ANT script set up to run WSDL2Java to put files in a different source tree, 'build/generatedSrc', which has the same structure as my 'src' tree.Then I have an ANT target which generates files into the 'generatedSrc' tree.If I want to modify a file (a skeleton file, for instance), I copy the file from my generatedSrc tree to my src tree, modify it as desired, and then modify my ANT script to automatically delete it from the generatedSrc tree after each time that WSDL2Java is run.That way, I can be sure that none of my modified files have been overridden. I think it's unwise to generate files into a directory where non-generated files sit. (Also, keeping them separate allows me to make sure, for instance, that the generated files don't get checked into version control.)When compiling, I just include both source tree roots in the 'javac' ANT target.Derek-----Original Message-----
From: Amit Andhale [mailto: [EMAIL PROTECTED]]
Sent: Monday, July 31, 2006 12:34 AM
To: [email protected]
Subject: Axis 1.3 WSDL2Java Overwrites the original filesHi All,When I run WSDL2Java command, it generates the Stub files, which also overrides my existing files.Could you please help me in this context?RegardsAmit
