4

I am trying to follow this Apache CXF – JAX-WS – Simple Tutorial but building the downloaded sample (out of the box!) creates a client that upon invocation refuses to run, issuing this error:

Failed to load Main-Class manifest attribute from SampleWSCxfClient-0.0.1-SNAPSHOT.jar

I searched to find out more about this problem and found out this SO answer which prompted me to hack SampleWSCxfClient-0.0.1-SNAPSHOT.jar by opening it using 7-zip and adding into a file name META-INF/MANIFEST.MF the following line:

Main-Class: com.areyes.sample.client.SampleWSClient

I figured out that main class by simply looking at the only Java file in the project:

package com.areyes.sample.client;

import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.sample.service.SampleWebService;

public class SampleWSClient {


    public SampleWSClient() {

        ClassPathXmlApplicationContext classPathXmlAppContext = new ClassPathXmlApplicationContext("classpath:META-INF/beans.xml");
        classPathXmlAppContext.start();

        SampleWebService sampleWebService = (SampleWebService)classPathXmlAppContext.getBean("client");

        System.out.println(sampleWebService.getDataFromWebService().getName());
        System.out.println(sampleWebService.getDataFromWebService().getDescription());
        System.out.println(sampleWebService.getDataFromWebService().getAge());

    }

    public static void main(String[] args){
        new SampleWSClient();
    }
}

I then tried to invoke SampleWSCxfClient-0.0.1-SNAPSHOT.jar again, but this time it fails with:

Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/context/support/AbstractApplicationContext
Caused by: java.lang.ClassNotFoundException: org.springframework.context.support.AbstractApplicationContext
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: com.areyes.sample.client.SampleWSClient. Program will exit.

How do I make this sample work?


For your convenience, the entire sample package ZIP can be downloaded from here.

Community
  • 1
  • 1
Introspective
  • 554
  • 2
  • 5
  • 13
  • 1
    Just to check: you're using Maven to build it, right? – Joe Rinehart Jan 08 '14 at 21:44
  • @JoeRinehart Yes, I do. and the `pom.xml` already contains the `spring-context` dependency. You can actually see the entire project package verbatim [here](https://dl.dropboxusercontent.com/u/1737239/SampleWSCxf.zip). Why a complete tutorial package doesn't work out-of-the-box is beyond me. Thanks! – Introspective Jan 08 '14 at 21:45
  • Yeah, that's what kind of threw me - I downloaded it and it's right there in the POM. How are you trying to run it / what's creating a classpath to include everything? – Joe Rinehart Jan 08 '14 at 22:31

3 Answers3

3

I once came across a similar problem and after being unable to decipher the magic of running "a jar with many dependencies" from the command line, I worked around it by running it through Maven.

Try this:

mvn exec:java -Dexec.mainClass=com.areyes.sample.client.SampleWSClient
Withheld
  • 4,603
  • 10
  • 45
  • 76
0

for maven based projects, please follow the below link to create runnable jar. For maven based project, making jar using export->jar option doesnt work. It work for me successfully.

CREATING RUNNABLE JAR for maven based eclipse project

sayan
  • 501
  • 2
  • 7
  • 21
0

I had the same problem but it got fixed after I updated the classpathPrefix in my pom.xml. Support_lib/ .

After you build the project using maven, the 'target' folder had this Support_lib/ dir with all the spring jar files in it. so I used this dir name in the classpathPrefix and it worked.