taskdef class com.sun.tools.ws.ant.WsImport cannot be found Following "The java web services tutorial"
Asked Answered
P

11

18

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>
Philipson answered 23/2, 2011 at 13:31 Comment(5)
What does your <taskdef> look like? Include the classpath you're using.Laveta
@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. UpdatingPhilipson
...and how is jaxws.classpath defined?Laveta
...and you should also specify which version of JAX-WS and Ant you're using...Laveta
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.3Philipson
M
22

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

Mcloughlin answered 18/6, 2013 at 1:43 Comment(6)
Do not currently have the resources to check, could someone else with the same problem try and inform?Philipson
You don't have the resources to check for what?Mcloughlin
I do not have the time to check you solution to see if it is true (download netbeans install it and follow the steps). If someone else can confirm it, I can choose the answer as correct :-)Philipson
Worked with Netbeans 8.2 on Centos 7. I installed my netbeans in the folder netbeans-8.2rc inside my home filder, so the complete path to the jars is /home/my_user/netbeans-8.2rc/enterprise/modules/ext/metro/Phosphorescence
New Path: "C:\Program Files\NetBeans-11.1\netbeans\enterprise\modules\ext\metro"Bats
This also works with Netbeans 12.6. New path: C:\Program Files\NetBeans-12.6\netbeans\enterprise\modules\ext\metroPhosphorescence
H
13

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.

Hemangioma answered 6/6, 2011 at 10:26 Comment(1)
since the solution link is now a dead end, it's kind of nice that you put the code here!Denis
N
9

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>
Nureyev answered 22/9, 2011 at 14:25 Comment(0)
L
4

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".

Laveta answered 24/2, 2011 at 18:39 Comment(1)
I feel I am close, but not there yet (added how the endorsement location looks in the question body above), I have the following output: BUILD FAILED c:\javaeetutorial5\kschneid\build.xml:9: 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:\Sun\jaxws-ri\lib\jaxws-tools.jar;C:\Sun\jaxws-ri\lib\jaxws-rt.jar;C:\Sun\jaxws-ri\lib\jaxws-api.jar;C:\Sun\jaxws-ri\lib\jsr181-api.jar;C:\Sun\jaxws-ri\lib\jsr250-api.jar;C:\Sun\jaxws-ri\lib\saaj-api.jar;...] Total time: 0 secondsPhilipson
P
2

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

Papaverine answered 9/10, 2015 at 1:41 Comment(0)
L
2

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

Lauralee answered 27/10, 2015 at 11:42 Comment(0)
G
1

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/

Goldina answered 26/2, 2014 at 14:11 Comment(0)
P
0

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?)

Philipson answered 24/2, 2011 at 9:31 Comment(2)
i think i'm having the same experience. i was hoping to just use the ant build.xml created by netbeans to create my ws that depends on other ws. but i'm having this issue below. would love to hear if you got your situation resolved.Douty
Unfortunately I had to abandon the (educational) project, this is the reason I have not chosen an answer up until now. What I've got out of it is that the documentation on Sun's site is outdated. At some consumption scenarios I encountered later on, I happened to use RESTful interfaces, so I did not had the necessity to dwell into web services. Will update when something changes...Philipson
E
0

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

Exceed answered 12/7, 2014 at 15:31 Comment(0)
G
0

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!

Geraud answered 14/9, 2016 at 9:17 Comment(0)
T
0

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".

Towardly answered 20/8, 2019 at 13:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.