views:

96

answers:

3

Hi all! I'm working at a spring-integrated Eclipse RCP application,but i got a error while spring framework initializing at application start.

My code in Activator.java below:

...
    public void start(BundleContext context) throws Exception {
        super.start(context);

        initializeApplicationContext();

        plugin = this;
    }

    private void initializeApplicationContext() {
        ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
        try {
            Thread.currentThread().setContextClassLoader(
                    this.getClass().getClassLoader());
            ctx = new ClassPathXmlApplicationContext(SPRING_CONFIGS);
        }catch(Exception e){
            e.printStackTrace();
        } finally {
            Thread.currentThread().setContextClassLoader(oldLoader);
        }
    }
...

The exception is:

2010-07-13 16:38:42,421 INFO  [AbstractApplicationContext] - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@be76c7: display name [org.springframework.context.support.ClassPathXmlApplicationContext@be76c7]; startup date [Tue Jul 13 16:38:42 CST 2010]; root of context hierarchy
2010-07-13 16:38:42,656 INFO  [XmlBeanDefinitionReader] - Loading XML bean definitions from class path resource [applicationContext.xml]
org.springframework.beans.factory.BeanDefinitionStoreException: I/O failure during classpath scanning; nested exception is java.io.FileNotFoundException: JAR entry net/interttimes/ not found in D:\Workspaces\MyEclipse 8.x\formicary-client2\lib\formicary-remote.jar
    at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:222)
    at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:201)
    at org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(ComponentScanBeanDefinitionParser.java:84)
    at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:69)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1297)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1287)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:135)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:92)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:507)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:398)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212)
    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:113)
    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:80)
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:123)
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:422)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
    at net.interttimes.formicary.rcp.Activator.initializeApplicationContext(Activator.java:62)
    at net.interttimes.formicary.rcp.Activator.start(Activator.java:47)
    ...
Caused by: java.io.FileNotFoundException: JAR entry net/interttimes/ not found in D:\Workspaces\MyEclipse 8.x\formicary-client2\lib\formicary-remote.jar
    at sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection.java:122)
    at sun.net.www.protocol.jar.JarURLConnection.getJarFile(JarURLConnection.java:71)
    ... 65 more

My formicary-remote.jar's package name is start with 'net.interttimes.',so i don't understand it,why the package name cannot be parsed ?

Thank you for attention to my question!

A: 

I think this may be down to the fact that JAR files (which are basically ZIP files) have an entry per file and the path of that file is stored in its entry and there doesn't have to be an entry for any of the directories in that file's path (although this is allowed).

You can check the files in your JAR using

jar -tf <jar_file>

If you don't see a separate line for the directory you are searching for, that may explain why you get a FileNotFoundException.

For example, for an entry:

a/b/c.txt

The directories 'a' and 'b' do not necessarily have their own entries in the JAR (unless you add them separately).

You'd see something like this, if so:

a
a/b
a/b/c.txt
fd
thank you! i checked my jar file using 'jar -tf',output:META-INF/MANIFEST.MFnet/interttimes/formicary/remote/IRegistHessianService.class...
newton
A: 

Have a look inside the jar file (which is actually a zip as we all know), spring expects a path

/net/interttimes/

inside. Sometimes while jar'ing the classes we accidently add the bin folder to the jar and have something like

/bin/net/interttimes/

(that's would be my most common mistake..)

Andreas_D
A: 

Thanks all of you!

My problem resolved. It because I used eclipse to export jar and did not check the 'Add directory entries' option. It works after i check this option. ^_^

newton