1

I have a set of related Java applications that are organized in an Apache Maven project like the following:

/project/
    module1/
    module2/
    module3/
    ...

The modules have different java packages, although they do have a common base package hierarchy. Some modules contain code for separate standalone applications. Each application is configured at run time via an XML file, which has a defining XML schema. Each application's schema and configuration is unique to the application. The schema definitions are translated into java classes via JAXB/XJC.

Consider a utility class in a module that can be used by one or more of the applications. The utility class is configured by XML defined by an XML schema. The schema is located in the same module as the utility class.

I'm trying to figure out how to configure the schemae so that the utility configuration can be included in the XML configuration of client applications.

For example:

Suppose the utility XML schema is like the following:

<xs:schema ...>
  <xs:complexType name="ConfigTypeA">
    <xs:sequence>
      <xs:element name="config-a-1" type="xs:string" />
      <xs:element name="config-a-2" type="ConfigTypeB" />
      ...
    </xs:sequence>
  </xs:complexType>
  ...
</xs:schema>

I would like to include the utility schema in the schema of a client application. So a snippet of a client app's schema could be:

  <xs:element name="app-util-config-a" type="ConfigTypeA">

From the XML schema perspective, I assume that either schema <include> or <import> elements would need to be used to provide the utility schema definitions to the client app's schema.

The Problem

The difficulty I'm running into here is providing the proper and correct URI to the utility schema. The schemae are simple and don't have a "URL" per se. The file: URI scheme makes sense, but I don't know how to set up the correct path in a dynamic way (i.e. for build and distribution purposes).

It doesn't make any sense to have a copy of the utility schema placed with the config schema of each application. Not only would I be duplicating, but the package of the resulting generated classes will not match the package of the utility class. This necessitates that I keep it in one place, and provide a correct URI to each of the application config schema.

I'm looking for ideas on how to best configure or organize this to achieve what I've described. I don't know enough about maven to know whether it has any capabilities to assist with this.

UPDATE: 08/07/2018 08:00 EDT

My posting was flagged as a potential duplicate and included several links to the possible related questions. I've looked at these and although they are related, don't quite cover what I'm running into.

Let me try to better describe the problem.

/project/
    module1/
        src/main/java/a/b/c/app1/...
        src/main/resources/config/app1-schema.xsd
    module2/
        src/main/java/a/b/c/app2/...
        src/main/resources/config/app2-schema.xsd
    module3/
        src/main/java/a/b/c/util/...
        src/main/resources/config/util-schema.xsd

Both app1 and app2 can use the utility in module 3. The utility is also configured at run time by XML defined by its own schema. Since none of these schema are being "served" in any way and do not have a URL, it appears that I have to use the URI file: scheme to reference a schema from elsewhere.

I would like to be able to reference the schema types defined in the utility schema, in the schemae for the applications. If I were to do this by hand, I would need to reference the full platform-specific directory path to where the utility schema resides in the <include> element in either of the application schemae.

This presents me with two problems to deal with: 1) specifying the correct file: paths for building purposes and 2) then again for when the built applications are installed and used.

This is impractical since it requires hardwired paths. Is there a way around this problem?

Joseph Gagnon
  • 1,731
  • 3
  • 30
  • 63

0 Answers0