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

No schemas to compile. Skipping XJC execution #449

Closed
SebasHein opened this issue Nov 7, 2023 · 17 comments
Closed

No schemas to compile. Skipping XJC execution #449

SebasHein opened this issue Nov 7, 2023 · 17 comments
Assignees
Labels

Comments

@SebasHein
Copy link

SebasHein commented Nov 7, 2023

Maybe this is related to #250 ?

I have a pom xml with several executions and their configuration. As long as the configuration which contains is contained in the execution the schema is not found.
As soon as I put the element out of the execution and directly below the plugin element it look like it works.

This does NOT work:

<plugin>    
    <groupId>org.jvnet.jaxb</groupId>    
    <artifactId>jaxb-maven-plugin</artifactId>    
    <version>4.0.0</version>    
    <executions>    
        <execution>    
            <id>xjc-1</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <generatePackage>some.package.name.1</generatePackage>
                <schemaDirectory>${project.basedir}/xjc/directory1/</schemaDirectory>
            </configuration>
        </execution>
        <execution>
            <id>xjc-2</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <generatePackage>some.package.name.2</generatePackage>
                <schemaDirectory>${basedir}/xjc/directory3/</schemaDirectory>
            </configuration>
        </execution>
        <execution>
            <id>xjc-3</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <generatePackage>some.package.name.3</generatePackage>
                <schemaDirectory>${basedir}/xjc/directory3</schemaDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

This does work for one xsd ...

<plugin>    
    <groupId>org.jvnet.jaxb</groupId>    
    <artifactId>jaxb-maven-plugin</artifactId>    
    <version>4.0.0</version>    
    <executions>    
        <execution>    
            <id>xjc-1</id>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>
	<configuration>
                <generatePackage>some.package.name.1</generatePackage>
                <schemaDirectory>${project.basedir}/xjc/directory1/</schemaDirectory>
    </configuration>
</plugin>

But I have three XSD files and they should result in three packages, one for each XSD.
Is there another way to do this?

@laurentschoelens laurentschoelens self-assigned this Nov 7, 2023
@laurentschoelens
Copy link
Collaborator

Hi @SebasHein
Thanks for using the plugin. Did you try specifying the generateDirectory for each execution ?
If not, please try with it specified with a different directory for each generation.
See sample pom.xml for example (which was created to test behavior of plugin regarding issue #250)
Regards
Laurent

@SebasHein
Copy link
Author

Hi @laurentschoelens
Thanks for you quick reply.
In the meantime I testet a lot of things and read ( hopefully carefull) through the sample pom.xml you mentioned above.

My XSD files are located in a folder structure like this
projectBaseDir\xjc\one\one.xsd
projectBaseDir\xjc\two\two.xsd
projectBaseDir\xjc\three\three.xsd
With the pom.xml is located in projectBaseDir

First I thought it was like this (which I cannot completely exclude - therefore I mention it):
Ff I do the following configuration it looks like it works.

<plugin>
	<groupId>org.jvnet.jaxb</groupId>
	<artifactId>jaxb-maven-plugin</artifactId>
	<version>4.0.0</version>
	<executions>
		<execution>
			<id>xjc-assembly</id>
			<phase>generate-sources</phase>
			<goals>
				<goal>generate</goal>
			</goals>
			<configuration>
				<schemaDirectory>${project.basedir}/xjc/one</schemaDirectory>
				<generateDirectory>${project.build.directory}/generate/v1</generateDirectory> 
				<generatePackage>some.package.name.v1</generatePackage>
				
			</configuration>
		</execution>

		<execution>
			<id>xjc-maskgroup</id>
			<phase>generate-sources</phase>
			<goals>
				<goal>generate</goal>
			</goals>
			<configuration>
				<schemaDirectory>${project.basedir}/xjc/two</schemaDirectory>
				<generateDirectory>${project.build.directory}/generate/v2</generateDirectory> 
				<generatePackage>some.package.name.v2</generatePackage>
				
			</configuration>
		</execution>
		<execution>
			<id>xjc-simulationresults</id>
			<phase>generate-sources</phase>
			<goals>
				<goal>generate</goal>
			</goals>
			<configuration>
				<schemaDirectory>${project.basedir}/xjc/three</schemaDirectory>
				<generateDirectory>${project.basedir}/generate/v3</generateDirectory> 
				<generatePackage>some.package.name.v3</generatePackage>
			</configuration>
		</execution> 
	</executions>
	<configuration>
	  <schemaDirectory>${project.basedir}/xjc/one</schemaDirectory>
	  <extension>true</extension>
	  <plugins>
		<plugin>
		  <groupId>org.jvnet.jaxb</groupId>
		  <artifactId>jaxb-plugins</artifactId>
		  <version>4.0.0</version>
		</plugin>
	  </plugins>
	</configuration>
</plugin>

This is weird :-)
As long as I give the plugin (and not the execution) a path to one of the xsd files and add in the executions the correct paths to the XSDs it looks like it works as expected.
As soon as the configuration element directly below the plugin definition no XSD is found at all.

BUT:
I tested always with mvn jaxb:generate - With this the above behaviour looks like it appears constantly.
When I do mvn install then it finds the XSDs without problem (and the executions are found to be in the output log).

Is there maybe something I did wrong with accessing the jaxb plugin during maven build?

@laurentschoelens
Copy link
Collaborator

Could you provide the output of mvn jaxb:generate ? With extra -X flag ?
What plugin is called by the jaxb:generate ?

You should also remove the <schemaDirectory>${project.basedir}/xjc/one</schemaDirectory> tag in the main <configuration> (outside <executions>)

@SebasHein
Copy link
Author

I did remove the schemaDirectory tag outside of executions.

I attached also the log of maven jaxb:generate as requested.
maven_jaxb_generate_log.txt

@laurentschoelens
Copy link
Collaborator

I did remove the schemaDirectory tag outside of executions.

I attached also the log of maven jaxb:generate as requested. maven_jaxb_generate_log.txt

If I do understand well, everything works as expected expect using mvn jaxb:generate ?

@laurentschoelens
Copy link
Collaborator

Well I'm not familiar with this jaxb:generate syntax but it seems to work but with only default execution, which is empty in your case.
Running mvn jaxb:generate on my project, I get jaxb:2.0.9:generate (default-cli)
Running mvn generate-sources on my project, I get jaxb:2.0.9:generate (generate-sources) which differs from previous.

As seen here, you can specify which execution you want to run with additional @ ref
For example, with my previous project, running mvn jaxb:generate@generate-sources, I get jaxb:2.0.9:generate (generate-sources), which is same as mvn generate-sources

Don't think this issue is related to plugin itself. @mattrpav any idea ?

@mattrpav
Copy link
Collaborator

mattrpav commented Nov 8, 2023

Heads up-- @laurentschoelens @SebasHein I'm tied up w/ ActiveMQ 6 release this week. I'll be able to take a look next week.

@laurentschoelens
Copy link
Collaborator

No problem, maybe you'd have some idea about short jaxb:generate mvn command

@laurentschoelens
Copy link
Collaborator

I understand now where the jaxb prefix came from
See ref here

@laurentschoelens
Copy link
Collaborator

@SebasHein
After some interesting search, I think you cannot use the jaxb:generate like you did before when using multiple executions like here
See here
Maybe the best option would be to have only one execution. Is there a need to split execution in 3 different parts ?

@laurentschoelens
Copy link
Collaborator

If you only need seperate package per xsd, please see this wiki page
Regards

@SebasHein
Copy link
Author

I will read all suggested hints as soon as possible.
For me, everything works fine as long as I do mvn package/install instead of calling a specific maven goal.

What I need is to have three different XSDs leading to Java classes in three different packages.
But let me first read what you suggest to read..

@laurentschoelens
Copy link
Collaborator

Hi @SebasHein : did you manage to make it work ?

@laurentschoelens
Copy link
Collaborator

Hello @SebasHein
Did you got any update for us ?
Can I close the issue ?

@SebasHein
Copy link
Author

First of all - sorry for the long delay. Short after writing the issues "end of the year" business catched me finally and I had no time for this. And I understood that @mattrpav wanted to investigate more and I was waiting for his answer...

I have three XSDs which should result each in an own package.
These XSDs I do not want to combine to one.
Therefore, as far as I understand, I need three executions.

In my case the observed behaviour is not really problematic in meaning that my build does fail.
I can always do mvn install and there it works like a charm.

The problem occurs only if I call the maven goal explicitely (mvn:generate).

So from my point of view you can close this issue unless @mattrpav has something against?

@laurentschoelens
Copy link
Collaborator

laurentschoelens commented Jan 16, 2024

I've pinged Matt since I didn't know about jaxb:generate short-goal and what it does.
I think you can combine the 3 XSD in one execution by providing a binding file which will do the package binding.

By doing so, your configuration should look like :

<plugin>
	<groupId>org.jvnet.jaxb</groupId>
	<artifactId>jaxb-maven-plugin</artifactId>
	<version>4.0.0</version>
	<configuration>
	  <schemaDirectory>${project.basedir}/xjc</schemaDirectory>
          <bindingDirectory>${project.basedir}/bindings</bindingDirectory>
	  <extension>true</extension>
	  <plugins>
		<plugin>
		  <groupId>org.jvnet.jaxb</groupId>
		  <artifactId>jaxb-plugins</artifactId>
		  <version>4.0.0</version>
		</plugin>
	  </plugins>
	</configuration>
</plugin>

And the following binding file bindings.xjb in the bindings directory would look like :

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings
  version="3.0"
  xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
  jaxb:extensionBindingPrefixes="xjc">

  <jaxb:bindings schemaLocation="xjc/one/the.xsd">
    <jaxb:schemaBindings>
      <jaxb:package name="some.package.name.v1" />
    </jaxb:schemaBindings>
  </jaxb:bindings>
  <jaxb:bindings schemaLocation="xjc/two/the.xsd">
    <jaxb:schemaBindings>
      <jaxb:package name="some.package.name.v2" />
    </jaxb:schemaBindings>
  </jaxb:bindings>
  <jaxb:bindings schemaLocation="xjc/three/the.xsd">
    <jaxb:schemaBindings>
      <jaxb:package name="some.package.name.v3" />
    </jaxb:schemaBindings>
  </jaxb:bindings>
</jaxb:bindings>

You can also look at the configuring target packages in binding files guide (with some adaptation) in the wiki.

@laurentschoelens
Copy link
Collaborator

Closing issue, which could be reopened if needed

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

No branches or pull requests

3 participants