0

I am developing a web service client in eclipse. I generated the artifacts for the web service using the wsimport goal of maven (see pom.xml below), and then wrote a simple client like this in a main method:

TeamsService service = new TeamsService();
Teams port = service.getTeamsPort();
List<Team> teams = port.getTeams();
for (Team team : teams) {
    System.out.println("Team name: " + team.getName() + " (roster count: " + team.getRosterCount() + ")");
    for (Player player : team.getPlayers())
                System.out.println(" Player: " + player.getNickname());
}

Unfortunately when I run the project in eclipse as a Java Application I get a ClassNotFoundException. I tried executing the client using the exec:java goal and it worked just fine, so I guess the problem may lie in the eclipse configuration (e.g. m2e plugin, or classpath).

I would really appreciate any help.

P.S: I am a newbie so maybe I am missing something basic here.

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.foo</groupId>
    <artifactId>JWSClients</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <dependencies>

        <dependency>
            <groupId>com.sun.xml.ws</groupId>
            <artifactId>jaxws-rt</artifactId>
            <version>2.2.8</version>
            <scope>runtime</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.jvnet.jax-ws-commons</groupId>
                <artifactId>jaxws-maven-plugin</artifactId>
                <version>2.3</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>wsimport</goal>
                        </goals>
                    </execution>
                </executions>

                <configuration>
                    <wsdlUrls>
                        <wsdlUrl>http://localhost:8888/teams?wsdl</wsdlUrl>
                    </wsdlUrls>
                    <sourceDestDir>${basedir}/src/main/java</sourceDestDir>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>

        </plugins>

        <pluginManagement>
            <plugins>
                <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>
                                            org.jvnet.jax-ws-commons
                                        </groupId>
                                        <artifactId>
                                            jaxws-maven-plugin
                                        </artifactId>
                                        <versionRange>
                                            [2.3,)
                                        </versionRange>
                                        <goals>
                                            <goal>wsimport</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore></ignore>
                                    </action>
                                </pluginExecution>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <properties>
        <encoding>UTF-8</encoding>
    </properties>
</project>

Stacktrace:

Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/istack/localization/Localizable
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:792)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:792)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:208)
    at com.sun.xml.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:112)
    at javax.xml.ws.Service.<init>(Service.java:77)
    at ch01.team.TeamsService.<init>(TeamsService.java:42)
    at ch01.team.Client.main(Client.java:7)
Caused by: java.lang.ClassNotFoundException: com.sun.istack.localization.Localizable
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 29 more

Maven log when executing exec:java

[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building JWSClients 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for org.eclipse.m2e:lifecycle-mapping:jar:1.0.0 is missing, no dependency information available
[WARNING] Failed to retrieve plugin descriptor for org.eclipse.m2e:lifecycle-mapping:1.0.0: Plugin org.eclipse.m2e:lifecycle-mapping:1.0.0 or one of its dependencies could not be resolved: Failure to find org.eclipse.m2e:lifecycle-mapping:jar:1.0.0 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced
[INFO] 
[INFO] >>> exec-maven-plugin:1.2.1:java (default-cli) @ JWSClients >>>
[INFO] 
[INFO] <<< exec-maven-plugin:1.2.1:java (default-cli) @ JWSClients <<<
[INFO] 
[INFO] --- exec-maven-plugin:1.2.1:java (default-cli) @ JWSClients ---
Team name: Abbott and Costello (roster count: 2)
 Player: Bud
 Player: Lou
Team name: Marx Brothers (roster count: 3)
 Player: Chico
 Player: Groucho
 Player: Harpo
Team name: Burns and Allen (roster count: 2)
 Player: George
 Player: Gracie
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.561s
[INFO] Finished at: Sat Aug 03 16:52:19 COT 2013
[INFO] Final Memory: 14M/154M
[INFO] ------------------------------------------------------------------------
antoniojxk
  • 127
  • 2
  • 10

1 Answers1

0

I created this same web service about a week ago. I made a new project in Eclipse and created packages ch01.teams.service and ch01.teams.client (package names are slightly different than in the book but same idea). This is a lot easier than dealing with Maven, and it worked for me.

If you want to continue using Maven, you may just need to get com.sun.istack.localization.Localizable into your classpath (I am not sure from the description if you have it or not). If you go to http://www.jarfinder.com/index.php/java/info/com.sun.istack.localization.Localizable you can see it is in jaxb-impl-2.1.8.jar so if you can download that jar and put it in your classpath you might be good to go.

Paul J Abernathy
  • 993
  • 2
  • 12
  • 25