Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc: Namespace handlers cannot be located in classpath with INDEX.LIST is used in jar [SPR-5705] #10375

Closed
spring-projects-issues opened this issue Apr 29, 2009 · 15 comments

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Apr 29, 2009

Dave Syer opened SPR-5705 and commented

Namespace handlers cannot be located in classpath with INDEX.LIST is used in jar and running with "java -jar". If you build a jar file and index the classpath for it as recommended in the JAR file specification, the namespace handlers are only located from the first jar file in the list.

Removing the INDEX.LIST from the jar file and using a Classpath: entry in the manifest instead works fine, as does running with "java -cp ..." (not using -jar).


Affects: 2.5.6

3 votes, 7 watchers

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Apr 29, 2009

Dave Syer commented

If using Maven to create the JAR file a workaround is to not use the <index/> option in the <archive/>, e.g.:

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-jar-plugin</artifactId>
	<configuration>
		<archive>
			<manifest>
				<mainClass>foo.TestMain</mainClass>
				<addClasspath>true</addClasspath>
				<classpathPrefix>lib/</classpathPrefix>
			</manifest>
		</archive>
	</configuration>
</plugin>
@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Apr 30, 2009

Costin Leau commented

Another workaround is to specify inside the index file all the entries inside the nested jars as well since otherwise these are ignored.
I'm not sure if there's a way to do that in Maven, but in Ant, the nested indexjar (inside the jar task) helps:
http://ant.apache.org/manual/CoreTasks/jar.html#indexjars

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Apr 30, 2009

Dave Syer commented

Another nice workaround is to use

java -Djava.ext.dirs=lib foo.TestMain

instead of java -jar.

In fact I would say this is better for a command line client because it doesn't depend on the jar manifest being linked to external resources in a secret hard-coded directory (lib).

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jun 7, 2009

Juergen Hoeller commented

Any idea why this is the case? We're simply calling ClassLoader.getResources("META-INF/spring.handlers")... What could we possibly do to make this work for jars including INDEX.LIST?

Juergen

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jun 8, 2009

Dave Syer commented

I think it's really a bug / misspecification of the Java runtime. For us it probably boils down to a documentation issue - strong advice not to use "java -jar", and if you do be careful with the manifest (especially if using Maven jar plugin, for which many examples in the public domain use the index feature).

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jun 29, 2009

ken p commented

I have tried the above mentioned workarounds. In my pom.xml I have the classpath being set to the manifest file. I also am ensuring that the index.list is not included in the jar file. When I run the jar files main class I get the following:

Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace http://www.springframework.org/schema/util
Offending resource: class path resource [applicationContext.xml]

at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:80)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:281)

Although, if I use maven to exec the main class (i assume which is basically java -cp ...) there is no issue. Ideas?

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 9, 2009

Max Bowsher commented

Having poked around in a debugger for a bit, this is entirely and completely a bug in the Sun Java implementation of jar indexing - not a bug in the specification.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Dec 2, 2009

Julio Argüello commented

As published on http://forum.springsource.org/showthread.php?t=81232 (bellow) I have the related problem using javaws (Java Web Start), any workaround?

Hi,

I'm developing a remote Java client application using a main jar file indexed according to SUN jar file specifications (http://java.sun.com/javase/6/docs/te...ml#JAR%20Index)

However there is a problem while trying to resolve pattern based resources. In fact, PathMatchingResourcePatternResolver just returns one single resource instead of getting all matching resources. Debugging, I have found that calling JNLPClassLoader#getResources("org/myorganization") returns only the first available jar.

Any solution?

Thanks in advance!!

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Mar 2, 2010

David Roussel commented

If we treat this as a documentation issue, then we need to update the documentation of the maven-jar-plugin so the documentation of the index option warns against switching it on when using java -jar. Do we need to open an issue in the maven-jar-plugin for this?

I would say the advice should be to not use jar indexing, as java -jar is more valuable. To use java -cp means you have to manage the classpath yourself, and also means you risk hitting the maximum command line length on Windows machines.

Does anyone know if this has been reported to sun? I had a quick search in the Sun bug database, but couldn't see anything relevant.

Anyone know where the source code to the classloader is? I couldn't step into it to see what's going on. Maybe from the code we can see a work around, like using a package outside of META-INF.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Mar 2, 2010

David Roussel commented

This is the most related bug I could find: http://bugs.sun.com/view_bug.do?bug_id=6887710

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented May 28, 2010

Julien HENRY commented

Same problem for me. I have a webstart application and I tried to add the INDEX.LIST to improve resource loading time. But as soon as I add the INDEX.LIST, Spring fails to start.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented May 28, 2010

Julien HENRY commented

In fact, the solution woul be to NOT put any resource in META-INF because only some default files are supported. See:
http://forums.java.net/jive/thread.jspa?messageID=292293#289192
http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html#The%20META-INF%20directory

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented May 30, 2010

Julien HENRY commented

See http://bugs.sun.com/view_bug.do?bug_id=2183678 for a workaround when using SUN jar command. Currently there is no way when using Maven to package.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jun 3, 2010

Julien HENRY commented

Sorry for the spam but after more investagation it is definitley a bug in java as explained by Max. When using jar indexing, getRessources() will only return the first instance found and not all instances. I have opened a bug on SUN database but it is still not visible (I think Oracle transition is in progress). Anyway here is the link I received by email in case it became public some day: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6957241

So for now the only workaround is to NOT use JAR indexing with webstart.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Sep 22, 2015

Juergen Hoeller commented

Closing groups of outdated issues. Please reopen if still relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.