15
votes

I saw the same issue in many different locations and even after a good portion of googling, I could not resolve it. What I am trying to do (the bigger picture) is to go through The java web services tutorial, which seems at points out of sync,

Specially here, when I try to compile, I get the following message:

C:\javaeetutorial5\examples\jaxws\common\targets.xml:26: taskdef class com.sun.tools.ws.ant.WsImport cannot be found

I have tried many different combinations of placing jars or changing environment variables, but with no result. Any successful stories?

The full build error message is the following:

BUILD FAILED

C:\javaeetutorial5\examples\jaxws\helloservice\build.xml:4: The following error occurred while executing this line:

C:\javaeetutorial5\examples\jaxws\common\targets.xml:26: taskdef A class needed by class com.sun.tools.ws.ant.WsImport cannot be found: org/apache/tools/ant/DynamicConfigurator

using the classloader AntClassLoader[C:\Program Files (x86)\Java\jdk1.6.0_23\lib\tools.jar]

Total time: 0 seconds

And the corresponding taskdef:

<taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport">
    <classpath refid="jaxws.classpath"/>
</taskdef>

Also a peek into the endorsement directory:

C:\javaeetutorial5\kschneid>cd %JAVA_HOME%

C:\Program Files (x86)\Java\jdk1.6.0_23>dir lib\endorsed
 Volume in drive C is OSDisk
 Volume Serial Number is AAAA-BBBB

 Directory of C:\Program Files (x86)\Java\jdk1.6.0_23\lib\endorsed

25/02/2011  09:34    <DIR>          .
25/02/2011  09:34    <DIR>          ..
25/02/2011  09:34           105,134 jaxb-api.jar
25/02/2011  09:33            54,476 jaxws-api.jar
               2 File(s)        159,610 bytes
               2 Dir(s)  110,907,056,128 bytes free

C:\Program Files (x86)\Java\jdk1.6.0_23>
11
What does your <taskdef> look like? Include the classpath you're using. - kschneid
@kschneid. I am sorry for not including all the details. Since many people start with this tutorial, I thought we'd meet the same obstacles. Updating - Dimitrios Mistriotis
...and how is jaxws.classpath defined? - kschneid
...and you should also specify which version of JAX-WS and Ant you're using... - kschneid
about jaxws.classpath. I do not know even if it is set (I was following a tutorial with no specific mention and I am new in this technology). Also I have downloaded JAXWS2.2.3 - Dimitrios Mistriotis

11 Answers

15
votes

You can fix the problem in Netbeans x.y as follows:

  1. Go to Tools->Options->Java->Ant.
  2. Click on "Add JAR/ZIP..." under the Classpath section
  3. Navigate to "C:\Program Files\NetBeans x.y\enterprise\modules\ext\metro\"
  4. Select all files.
  5. Click OK, and try the import/regenerate again.

where x.y = 7.1, 7.2, 8.0 etc

12
votes

Well, apparently a link to a website with the solution to this issue is unacceptable, so I'll paste the answer here:

<property name="BUILD_LIBS" location="C:/Projects/Build/Libs/" />

<taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport">
    <classpath>
        <pathelement location="${BUILD_LIBS}/jaxws-ri/lib/jaxws-tools.jar"/>
    </classpath>
</taskdef>

The issue is due to the relevant jaxws jar not being in the class path see the pathelement node above. Adding the jar to the classpath resolves the issue.

9
votes

The <wsimport> ant task is not included in the JDK, even though there is a wsimport.exe which does exactly the same.

If you really want the ant task, you can download jaxws-ri and use the 23(!) jars in the lib folder.

Or you can use this workaround by calling wsimport.exe:

<target name="generate-client" >
    <exec executable="${java.home}/../bin/wsimport">
        <arg line="-keep -d build/classes -p ebay.apis -s src -wsdllocation http://localhost:7070/Ebay?wsdl eBaySvc.wsdl"/>
    </exec>
</target>
4
votes

I fully support non-IDE development, especially when trying to learn something ;). Try starting with this simple build file (use the actual location of your JAX-WS RI install):

<project name="jaxws-tutorial" default="wsimport">

    <property name="jaxws.home" location="D:/jaxws-ri-2_2_1"/>

    <path id="wsimport.classpath">
        <fileset dir="${jaxws.home}/lib" includes="jaxws-tools.jar"/>
    </path>

    <taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport" classpathref="wsimport.classpath"/>

    <target name="wsimport">
        <wsimport>
            <arg value="-version"/>
        </wsimport>
    </target>

</project>

If you just run ant, you should see some output like the following:

wsimport:
 [wsimport] Consider using <depends>/<produces> so that wsimport won't do unnecessary compilation
 [wsimport] JAX-WS RI 2.2.1-b01-

Since it looks like you're using Java 6, pay attention to "Running on JDK6".

2
votes

I changed the classname="com.sun.tools.ws.ant.WsImport" to classname="com.sun.tools.ws.WsImport", which fixed this issue for me.

1
votes

This worked for me:

I download the JAVA-WS library from official site I put it on extra-lib directory. This directory is on the same level of build.xml. On build.xml I copy from jaxws-build.xml the Ant task named “wsimport-init” and I modify it as in the follow mode:

...
    <target name="wsimport-init" depends="init">
        <mkdir dir="${build.generated.sources.dir}/jax-ws"/>
        <taskdef name="wsimport" classname="com.sun.tools.ws.Ant.WsImport">
            <classpath>
                <fileset dir="./extra-lib">
                    <include name="**/*.jar"/>
                </fileset>
            </classpath>
        </taskdef>
    </target>
...

Reference: http://www.staniscia.net/989-resolve-the-portable-problem-of-netbean-jax-ws-libraries-for-web-service-clients/

1
votes

To get past this error we need to use Tools->Options, click Miscellaneous, and in the Ant tab use Add Jar/ZIP to locate and add the libraries webservices-tools.jar and webservices-rt.jar in the directory

1
votes

I had the same problem after testing Netbeans 11 and then going back to Netbeans 8.2. The solution was the file

ProjectName\nbproject\private\private.properties

that one had an entry

user.properties.file=XXXX\\AppData\\Roaming\\NetBeans\\11.0\\build.properties

changing it back to the correct installation

user.properties.file=XXXX\\AppData\\Roaming\\NetBeans\\8.2\\build.properties

solved the problem. For some projects Netbeans popped up a dialogbox "The project ProjectName uses build.properties from another Netbeans installation", then click "Use this installation".

0
votes

I found an answer which does not satisfy me at all: Installed netbeans which takes care of joining things together. Still the command line does not work (so that means that it is compartmentalised the environment which is good). I can follow up the tutorial, but I still believe that everything should be done from the command line (was there too much Unix in my diet?)

0
votes

Better still, you can use the command line tool wsimport to generate the jar or files

http://docs.oracle.com/javase/6/docs/technotes/tools/share/wsimport.html

generate the files into the build/classes folder, you can then reference it from there with ant javac

0
votes

If you are using Eclipse IDE and facing this issue, here is something that worked for me. Go to : Window > Preferences. Find the Ant option on the left side.

Expand it and you will find ANT Runtime. Select that option and check the jars included in the Classpath tab.

Select the Add External Jar's option. Now go to the ant home folder in your system. Go to the lib folder and add all the jars / missing jar files.

this will resolve the missing dependency for ant-build.

Hope That Helps!