开发者

Hibernate is not able to load a JAR file if my directory name contains space!

I have an application that is based on Swing, Spring 2.5.2, Hibernate 3.3.1.

If my application is run from a directory that contains a space character, for example D:\hudson\jobs\FooBar - Fast Build, then I get this error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [spring-persistence.xml]: Invocation of init method failed; nested exception is java.lang.RuntimeException: error trying to scan <jar-file>: file:/D:/hudson/jobs/FooBar%20-%20Fast%20Build/workspace/commons/target/classes/
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1302)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:463)
    ...
Caused by: java.lang.RuntimeException: error trying to scan <jar-file>: file:/D:/hudson/jobs/FooBar%20-%20Fast%20Build/workspace/commons/target/classes/
    at org.hibernate.ejb.Ejb3Configuration.scanForClasses(Ejb3Configuration.java:635)
    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:350)
    ...
Caused by: java.lang.RuntimeException: java.io.FileNotFoundException: D:\hudson\jobs\FooBar%20-%20Fast%20Build\workspace\commons\target\classes (The system cannot find the path specified)
    at org.jboss.util.file.JarArchiveBrowser.<init>(JarArchiveBro开发者_开发问答wser.java:74)
    at org.jboss.util.file.FileProtocolArchiveBrowserFactory.create(FileProtocolArchiveBrowserFactory.java:48)
    ...
Caused by: java.io.FileNotFoundException: D:\hudson\jobs\FooBar%20-%20Fast%20Build\workspace\commons\target\classes (The system cannot find the path specified)
    at java.util.zip.ZipFile.open(Native Method)
    at java.util.zip.ZipFile.<init>(ZipFile.java:114)
    at java.util.jar.JarFile.<init>(JarFile.java:133)
    at java.util.jar.JarFile.<init>(JarFile.java:97)
    at org.jboss.util.file.JarArchiveBrowser.<init>(JarArchiveBrowser.java:69)
    ... 49 more

(note that in this case, the error occurs during a unit test launched by a Hudson job)

As you can see, each space character is replaced by a %20 in the URL, which may be the source of the problem...

Do you have any idea why this happens, and how to solve it (of course, renamming the whole path of my application will solve the problem, but it is not the kind of answer that I am looking for ;) ) ?

ps: I don't know if it can help you, but the bean entityManagerFactory is created in the spring-persistence.xml file with the following definition:

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="oraclePersistenceUnit"/>
    <property name="dataSource" ref="dataSource"/>
</bean>

(the properties are defined in another place of the spring definition, or in a persistence.xml file)


The error is thrown when I run the following code in my application:

applicationContext = new ClassPathXmlApplicationContext("/my-spring-config.xml");

my-spring-config is located in the src/main/resources directory of my application.

I've also tested with a FileSystemXmlApplicationContext instead, but the problem still occurs.


The %20 is the normal way to URL-encode spaces.

Sounds like you are treating an URL like a plain filename, which is incorrect. How is this information passed down to Ejb3Configuration?


In fact, this is due to a bug in the version of hibernate-entitymanager I was using (3.3.1.ga).

By replacing this version with the latest one (3.4.0.GA), the problem does not occur anymore.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜