I use wsimport to generate my java stub files. For this, I use an ant build file in Eclipse:
<taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport">
<classpath>
<fileset dir="../lib">
<include name="jaxws-tools.jar" />
</fileset>
</classpath>
</taskdef>
<target name="generate">
<wsimport wsdl="../wsdl/Knowledgebase.wsdl"
destdir="../bin"
sourcedestdir="../gen"
keep="true"
xendorsed="true">
</wsimport>
</target>
The task runs without any errors. It creates different java-files, also Knowledgebase.java and KnowledgebasePort.java. In der Knowledgebase.java, there are these constructors:
public Knowledgebase(WebServiceFeature... features) {
super(__getWsdlLocation(), KNOWLEDGEBASE_QNAME, features);
}
For them I get an error "The constructor Service(...) is undefined". I imported the current jax-ws jar files. Is my generation process broken, do I use the wrong jars or where is the error?
The Service object is provided by the Java EE SDK. It added a new constructor between Java EE 5 and Java EE 6. It would seem the wsimport you're using is from a Java EE 6 JDK and the compiler is using a Java EE 5 SDK?
If we using for example java 1.6.0_27 and Metro 2.2 we need to ENDORSE the webservices-api.jar.
We have to put this jar into folder java-install-dir\jre\lib\endorsed\
In case of using Eclipse, we have to ensure that we are using the correct JRE from the directory java-install-dir. This is done in Window->Preferences->Java->Installed JREs->Add.
Now the error "The constructor Service(...) is undefined" should disappear.
You can set xendorsed="true" and xnocompile="false" and let ant compile your generated java files and it worked for me
<taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport">
<classpath>
<fileset dir="${ext.myproject.path}/lib">
<include name="*.jar"/>
</fileset>
<fileset dir="${platformhome}/resources/ant/lib">
<include name="*.jar"/>
</fileset>
</classpath>
</taskdef>
<macrodef name="myproject_before_compile_core">
<sequential>
<mkdir dir="${ext.myproject.path}/gensrc"/>
<mkdir dir="${ext.myproject.path}/classes"/>
<echo message="Generating WS stubs for Simulate BOM Service"/>
<wsimport wsdl="${ext.myproject.path}/resources/wsdl/service.wsdl" package="com.xx.energy.yy.xyz.ws.stubs.service" xnocompile="false" destdir="${ext.myproject.path}/classes" sourcedestdir="${ext.myproject.path}/gensrc" keep="true" wsdlLocation="${ext.myproject.path}/resources/wsdl" xendorsed="true">
<produces dir="${ext.myproject.path}/gensrc/com/xx/energy/yy/xyz/ws/stubs/service">
<include name="*.java"/>
</produces>
<depends file="${ext.myproject.path}/resources/wsdl/service.wsdl"/>
</wsimport>
</sequential>
</macrodef>
Related
I've got a NetBeans 14 free-form project using Ant. It utilizes wsimport in its build.xml, and a lot of the targets depend on wsimport. After ending up with several JDKs (at least 1.8 and 17) I'm having trouble building, from wsimport chosing the wrong JDK.
In the build.xml (extracts):
<taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport">
<classpath>
<pathelement location="${lib}/jaxws22/jaxws-tools.jar"/>
</classpath>
</taskdef>
<target name="wsimport">
<wsimport
wsdl="http://address/to/wsdl.xml"
catalog="${metainf}/jax-ws-catalog.xml"
destdir="${release}"
sourcedestdir="${src-gen}"
keep="true"
extension="true"
verbose="true">
<depends file="${metainf}/jax-ws-catalog.xml"/>
<depends file="${wsdl}/wsdl.xml"/>
<produces dir="${src-gen}"/>
</wsimport>
</target>
<target name="compile" depends="init,wsimport" description="compile the source">
<javac ... />
</target>
The problem is that when running wsimport seems to select JDK17, while I want it to select JDK1.8. The output is this:
command line: wsimportC:\path\to\jdk-17.0.2\bin\java.exe ... http://address/to/wsdl.xml
Which gives:
java.lang.NoClassDefFoundError: com/sun/org/apache/xml/internal/resolver/CatalogManager
at com.sun.tools.ws.wscompile.WsimportOptions.parseArguments(WsimportOptions.java:317)
...
Which I've got down to not working with JDK 17. How can I make wsimport use the correct JDK in this scenario?
Below is the code for setting class path in ant.
<path id="build.classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
</path>
<target name="compile" depends="clean">
<javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="build.classpath" />
</target>
Why do we need to set classpath in ant ?
Think of ant as a framework to run your build tasks - compiling the code, running the (unit) tests, etc. In order to properly compile and execute your (test) code, java will need access to the third party libraries you may be using (e.g., JUnit for running unit tests). The classpath tells java where these JARs are located, so it can use them.
I am trying to convert a web service from using the version of ant that comes with weblogic (OFM 11G Release 1 (10.3.6)) to a newer, standalone version of ant (1.8.4). During the build with 1.8.4 I am receiving the following warnings which I would like to eliminated if possible. The warning occurs with all exception classes in the project. Can anyone provide a suggestion? I am new to weblogic web services.
[jwsc] [WARNING] skipping exception constructor for ca.bc.gov.webade.WebADEException: could not find property corresponding to ctor param 'arg0' on public WebADEException(java.lang.String,java.lang.Exception)
Here is the JWSC portion of the build file. The task is defined using the same paths as part of the build classpath below. The weblogic paths correspond to to WLS_HOME and MODULES_DIR environment variables as set by weblogic.
<target name="jwsc" depends="compile">
<path id="JWSCclasspath">
<fileset dir="${lib.dir}">
<include name="*.jar"/>
</fileset>
<fileset dir="${webade.lib.dir}" includes="*.jar" />
<!-- Reference compiled classes rather than jar file due to issue deleting the jar file at the end of the build -->
<pathelement path="${build.bus.dir}"/>
<pathelement path="{weblogic.dir}"/>
<fileset dir="${weblogic.dir}" >
<include name="*.jar" />
</fileset>
<pathelement path="${weblogic.modules}" />
<fileset dir="${weblogic.modules}" >
<include name="*.jar"/>
</fileset>
</path>
<jwsc srcdir="${src.dir}" destdir="${deploy.dir}" classpathref="JWSCclasspath">
<jws file="${war.path}/MapViewerServicesPortTypeImpl.java" type="JAXRPC">
<WLHttpTransport contextPath="mapViewer" serviceUri="MapViewerWS" portName="MapViewerServicesPort"></WLHttpTransport>
</jws>
</jwsc>
</target>
I am new to Java programming. I initially started with NetBeans but have moved to Eclipse given the advice from a friend.
In NetBeans, a pre-written ant build script for the project would generate a Project.jar file and place all required libraries/jars in a lib/ folder.
However, in Eclipse it appears that I need to write my own ant script. I have written a few lines to generate the jar file:
<target name="compile">
<mkdir dir="${build.dir}"/>
<javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="jars" debug="on"/>
</target>
How do I write a command to copy all of the jars in my User Library to a ${build.dir}/lib/ folder?
Thanks.
Use the copy task
like so, with the appropriate include or exclude pattern
<copy todir="${build.dir}/lib/">
<fileset dir="src_dir">
<include name="**/*.jar"/>
</fileset>
</copy>
<copy todir="${build.dir}/lib/">
<fileset dir="src_dir" excludes="**/*.java"/>
</copy>
If you are new to Java take the chance to have a look at maven. It is a build tool like ant with a lot of predefined 'goals' and a fully developed dependency (to other libraries) handling. You will find a eclipse plugin which will be very useful.
Maven projects have a special directory layout which is kind of best practise and helpful for beginners. If you work on a maven project you can just use the command
mvn dependency:copy-dependencies
as a console command (or eclipse run configuration) to copy your project dependencies (libraries) to the <project>\target\dependency directory.
I recommend to use ant4eclipse library for ant based eclipse projects. When you use it, you can access eclipse workspace/project settings, and can iterate tought eclipse project class path in ant.
See the example code bellow:
<path id="ant.classpath">
<fileset dir="${lib.dir}/ant4eclipse">
<include name="*.jar" />
</fileset>
<taskdef resource="net/sf/antcontrib/antlib.xml" />
<taskdef resource="net/sf/ant4eclipse/antlib.xml" />
<targetPlatform
<target name="copy_jars">
<getEclipseClasspath workspace="${basedir}/.."
projectname="TestProject"
targetPlatformLocation="c:/eclipse"
property="classpath"
relative="false"
runtime="true"
pathseparator="#" />
<!-- iterate over all classpath entries -->
<foreach list="${classpath}" delimiter="#"
target="copy_jar_file" param="classpath.entry" />
</target>
<target name="copy_jar_file">
<!-- check if current is a .jar-file ... -->
<if>
<isfileselected file="${classpath.entry}">
<filename name="**/*.jar" />
</isfileselected>
<then>
<!-- copy the jar file to a destination directory -->
<copy file="${classpath.entry}" tofile="${dest.dir}"/>
</then>
</if>
</target>
If you would like to use user libraries, you can define it by userlibraries command.
We are in the process of upgrading from BEA Weblogic and ALSB to Oracle Weblogic and OSB 10.3.4. One of the things that are failing is our ant task for compiling jsp pages for our WAR.
This is the part of the ant build file that is failing now:
<!-- Compile the JSP files -->
<path id="workshop.classpath">
<fileset dir="${env.WL_HOME}/workshop/lib">
<include name="*.jar"/>
</fileset>
<pathelement location="${env.ORACLE_HOME}/tools/eclipse_pkgs/1.1/pkgs/eclipse/plugins/com.bea.workshop.wls.ant_1.0.20.200802230117/workshop-wls-antlib.jar"/>
</path>
<taskdef
name="jspc"
classname="com.bea.workshop.wls.antlib.tasks.JspcTask" classpathref="workshop.classpath"/>
<path id="jspc.classpath">
<path refid="java.classpath"/>
<pathelement location="${env.ORACLE_HOME}/jdk150_11/lib/tools.jar" />
<pathelement location="${env.WL_HOME}/server/lib/weblogic.jar" />
</path>
<jspc source="#{war.staging.dir}" classpathref="jspc.classpath" failonerror="true" />
It cannot resolve the jar file with JspcTask since Workshop does not exist in 10.3.4. So the question is, how should this ant script be changed to work under 10.3.4?
The taskdef with the classname below works with WLS 10.3.3
<taskdef name="jspc"
classname="weblogic.ant.taskdefs.j2ee.Jspc" classpath="{ORACLE_MIDDLEWARE_HOME}\wlserver_10.3\server\lib\weblogic.jar">
</taskdef>
Check your weblogic.jar with winzip/winrar to see if the above classname exists in 10.3.4, and it should be fine.
Update:
You're getting the NullPointer because jspc does not allow a directory in the source attribute. It should be srcdir as per the docs, in fact I dont see a source attribute at all.
The jspc task is deprecated, so I think it's better you use the weblogic.appc like below
<target name="compileapp">
<java classname="weblogic.appc" fork="yes">
<arg line="-webapp ${src.gui}" />
<arg value="-compiler javac" />
<arg line="-classpath D:\Oracle\Middleware_Jdev11_1_1_4\wlserver_10.3\server\lib\weblogic.jar" />
<arg value="-depend" />
<arg value="-nowarn" />
</java>
</target>
Choose the attributes you want from this list, I havent tried this myself yet.