Search code examples
javamaven-2xmlbeans

Accessing XMLBeans generated schemas.jar in Maven project


I have a schemas.jar supplied to me and am trying to access it from within a simple Maven project. I have put the schemas.jar file in my src/main/resources directory, which is in my classpath.

When I am trying to access the created documents with something like:

GetOrdersRequestDocument getOrdersRequestDocument = GetOrdersRequestDocument.Factory.newInstance();

It complains about the GetOrdersRequestDocument (can't find it).

How do I get the project to pick up these classes? Do I need to import anything specific?


Solution

  • I have put the schemas.jar file in my src/main/resources directory, which is in my classpath.

    Yes, the files in src/main/resources directory are on your classpath. But this doesn't mean that the content of the jar itself is directly available. You could use a URLClassLoader to load the JAR though.

    But... this is not how I would do things. If this is an option, I would just install the JAR in your corporate or local repository (using install:install-file) and declare it as a dependency. This would make the content of your JAR available to your code, like any other dependency.