10

I'm using the xjc plugin in Maven environment and trying to generate classes from the Schema I'm able to do this (Create classes) using xjc from command line, but unable to do the same using maven target generate-sources.
Getting the following exception

[ERROR] null[5,30] org.xml.sax.SAXParseException: A class/interface with the same name "<className>" is already in use. Use a class customization to resolve this conflict. at com.sun.tools.xjc.util.CodeModelClassFactory.createClass(CodeModelClassFactory.java:100) at com.sun.tools.xjc.util.CodeModelClassFactory.createClass(CodeModelClassFactory.java:61) at com.sun.tools.xjc.generator.bean.ImplStructureStrategy$1.createClasses(ImplStructureStrategy.java:42) at com.sun.tools.xjc.generator.bean.BeanGenerator.generateClassDef(BeanGenerator.java:371) at com.sun.tools.xjc.generator.bean.BeanGenerator.getClazz(BeanGenerator.java:403) at com.sun.tools.xjc.generator.bean.BeanGenerator$1.onBean(BeanGenerator.java:291) at com.sun.tools.xjc.generator.bean.BeanGenerator$1.onBean(BeanGenerator.java:299) at com.sun.tools.xjc.model.CClassInfo.accept(CClassInfo.java:352) at com.sun.tools.xjc.generator.bean.BeanGenerator.getContainer(BeanGenerator.java:281) at com.sun.tools.xjc.generator.bean.BeanGenerator.getUsedPackages(BeanGenerator.java:337) at com.sun.tools.xjc.generator.bean.BeanGenerator.<init>(BeanGenerator.java:169) at com.sun.tools.xjc.generator.bean.BeanGenerator.generate(BeanGenerator.java:151) at com.sun.tools.xjc.model.Model.generateCode(Model.java:230) at com.sun.tools.xjc.Driver.run(Driver.java:317) at org.codehaus.mojo.jaxb2.XjcMojo.execute(XjcMojo.java:301) at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138) at org.apache.maven.cli.MavenCli.main(MavenCli.java:362) at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315) at org.codehaus.classworlds.Launcher.launch(Launcher.java:255) at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430) at org.codehaus.classworlds.Launcher.main(Launcher.java:375) 

Can anyone help me find whats missing here.

5
  • Are you using any binding file? can we see your POM configuratoin for the plugin? Commented May 22, 2011 at 8:09
  • What is the package name for the conflicted class? Commented May 24, 2011 at 18:46
  • As rhinds said, need more details. Can we see your pom configuration for the plugin, and also your command line from which it seems to be working. And if at all possible the actual xsd schema Commented May 25, 2011 at 0:50
  • THe problem seems to be with the way the schemas are defined. As one schema extends the other and xjc is trying to generate classes for both and is failing with the above error. Commented May 25, 2011 at 9:52
  • 1
    Since your use case works from the command line the issue is probably not related to the XML Schemas themselves. Commented May 25, 2011 at 11:20

3 Answers 3

4
+25

As stated on the JAXB site, use the following Maven plugin:

 <plugin> . <groupId>org.jvnet.jaxb2.maven2</groupId> <artifactId>maven-jaxb2-plugin</artifactId> <executions> <execution> <goals> <goal>generate</goal> </goals> </execution> </executions> </plugin> 

http://java.net/projects/maven-jaxb2-plugin/pages/Home

http://jaxb.java.net/

It seems, you're using a different plugin (org.codehaus.mojo.jaxb2.XjcMojo on your stack trace for which Google leads me to http://mojo.codehaus.org/jaxb2-maven-plugin/ ).

Sign up to request clarification or add additional context in comments.

4 Comments

THe plugin is fine but the issue is with the schemas as i have two schemas with one extending the other.
You said it works from command line, but it fails from the plugin, so there might be an issue with the plugin. E.g. it might be that you need episode support and that plugin doesn't support episodes?
from the commandline, if I execute each schema separately, it was working.
Again: 1. provide the exact commands you're executing, which are working 2. show us the plugin configuration you're using (for the recommended plugin I mentioned)
1

Since it works command line but not in Maven the class with the conflict must appear somewhere on your classpath. Any chance that is happening?

For an example on how to resolve name conflicts see:

1 Comment

No, its not in the classpath.
1

May be you have two sub-elements with the same name, so the generated class name is the same?

If this is the case, you can customized the produced class name using the schema annotations:

First add the following namespaces to your xsd:

<xs:schema xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="2.0"> 

Second add annotation for the relevant element:

<xs:complexType name="ComplexType"> <xs:annotation><xs:appinfo> <jaxb:class name="MyClass"> <jaxb:javadoc>This is my class.</jaxb:javadoc> </jaxb:class> </xs:appinfo></xs:annotation> </xs:complexType> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.