views:

261

answers:

3

Hi,

I wrote my own custom namespace for a Spring based project I'm working on. The project is built with maven, and I'd like to put my xsd files in the resources directory. The problem is the spring.schemas directory requires me to define where I put my xsd file. In my dev environment it will be resources/schemas/myschema.xsd. But, when I compile, the contents of the resources get copied to target, not the target directory itself. So in the compiled code, I end up with target/schemas/myschema.xsd. Should my spring.schemas file reference resources/schemas/myschema.xsd? Or just schemas/xsd?

thanks,

Jeff

A: 

You can define a linked location in Eclipse. By using a variable to define your workspace root and then creating a linked folder you maintain some measure of portability.

Right-click on the project, select new->Folder

call the folder "schemas", click Advanced>>, select Link to folder in the file system

Select Variables... and pick the WORKSPACE_ROOT variable

Add the relative path to your schemas folder, e.g. [project name]/src/main/resources/schemas

When you finish you'll have a new schemas folder with a little arrow in the corner showing it is linked. You may find you need to force refreshes to get new files to be reflected in the linked location.

Rich Seller
+1  A: 

When creating a custom namespace for Spring the spring.schemas file should be located in META-INF with an entry like this:

http\://www.springframework.org/schema/context/spring-context-2.5.xsd=org/springframework/context/config/spring-context-2.5.xsd

Your custom schema should be then in src/main/resources/org/springframework/context/config/ to be added in the classpath of the project.

Any good IDE should understand src/main/resources/ as a source code folder and read the schema just well.

NOTE: I pulled this example from the spring-core.jar, just examine it yourself

victor hugo
thank you for the example. I do have it all working, I think there is an IDE issue though - could you take a look at the comment I posted above? thanks.
Jeff Storey
Have you tried to 'cleaning' your project? What Maven plugin do you use?
victor hugo
I added an entry to Eclipse so it knew how to resolve my XSD file and now all works well.
Jeff Storey
+1  A: 

Hi,

It should only point to schemas/myschema.xsd

target/resources will end up in your classpath so you can safely reference everything there.

pjesi
thanks, that's what I have done, but my bean definition xml file, eclipse just shows a red error mark in the right hand gutter (without any error description) even though everything works well. the auto-complete even works on my custom namespace, so it's obviously finding the schema. any idea why this would happen?
Jeff Storey