Compilation Failure when compiling class generated by jaxb - java

I have these error when compiling classes generated by JAXB with annotation:
annotations are not supported in -source 1.3 (use -source 5 or higher
to enable annotations) #XmlAccessorType(XmlAccessType.FIELD)
annotations are not supported in -source 1.3 (use -source 5 or higher
to enable annotations) #XmlRegistry
...
For all of the annotation.
I have tried with jdk 1.6 or jdk1.7, both lead to the same error.
Any one have seen this before ?
I am using maven-compiler-plugin
[DEBUG] Trace org.apache.maven.BuildFailureException: Compilation
failure at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:715)
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) Caused
by: org.apache.maven.plugin.CompilationFailureException: Compilation
failure at
org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:516)
at
org.apache.maven.plugin.CompilerMojo.execute(CompilerMojo.java:114)
at
org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
... 17 more
Thank you,
Khue.

By default the Maven compiler plugin tries to compile at the lowest level of Java possible. So even though you are using Java 6 or 7 it is trying to compile a Java 1.3 application. You can change it by adding the following to your pom:
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>

Related

Failure executing javac, but could not parse the error: How to find which source file caused error?

I know there has been several other questions where someone had a problem because they got a similair error compiling, but it isn't quite the same error. In their case the problem seemed to be that Maven didn't have the path to the correct compiler. In my case the problem appears to be that there is an incorrectly written class/type somewhere.
Result when compling:
COMPILATION ERROR :
-------------------------------------------------------------
Failure executing javac, but could not parse the error:
An exception has occurred in the compiler (1.8.0_20). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you.
java.lang.ClassCastException: com.sun.tools.javac.code.Type$ErrorType cannot be cast to com.sun.tools.javac.code.Type$ArrayType
at com.sun.tools.javac.comp.Attr$TypeAnnotationsValidator.validateAnnotatedType(Attr.java:4637)
at com.sun.tools.javac.comp.Attr$TypeAnnotationsValidator.visitMethodDef(Attr.java:4485)
at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:778)
at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
at com.sun.tools.javac.comp.Attr$TypeAnnotationsValidator.visitClassDef(Attr.java:4552)
at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:693)
at com.sun.tools.javac.comp.Attr.validateTypeAnnotations(Attr.java:4451)
at com.sun.tools.javac.code.TypeAnnotations$2.run(TypeAnnotations.java:142)
at com.sun.tools.javac.comp.Annotate.flush(Annotate.java:155)
at com.sun.tools.javac.comp.Annotate.enterDone(Annotate.java:129)
at com.sun.tools.javac.comp.Enter.complete(Enter.java:512)
at com.sun.tools.javac.comp.Enter.main(Enter.java:471)
at com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:982)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:857)
at com.sun.tools.javac.main.Main.compile(Main.java:523)
at com.sun.tools.javac.main.Main.compile(Main.java:381)
at com.sun.tools.javac.main.Main.compile(Main.java:370)
at com.sun.tools.javac.main.Main.compile(Main.java:361)
at com.sun.tools.javac.Main.compile(Main.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.codehaus.plexus.compiler.javac.JavacCompiler.compileInProcess(JavacCompiler.java:554)
at org.codehaus.plexus.compiler.javac.JavacCompiler.compile(JavacCompiler.java:161)
at org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:605)
at org.apache.maven.plugin.CompilerMojo.execute(CompilerMojo.java:128)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
ErrorType (https://docs.oracle.com/javase/7/docs/api/javax/lang/model/type/ErrorType.html) means that some kind of class or Interface etc isn't written correctly and can't be modelled.
ArrayType just means it was an array. So most likely this means that somewhere I am using an incomplete/missing class as an array.
Also this was in visitMethodDef() -> validateAnnotatedType() meaning that perhaps this is the return type/parameter for a method?
What could be causing this? Why doesn't the compiler say where in the source code this happend?
Im using Maven 2.4 and JDK 1.8. I normally don't have any problems with compiling.
Here is a snippet of my maven pom.xml file:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>PATH.TO.MAIN.CLASS</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.fxml</include>
<include>**/*.css</include>
<include>**/*.properties</include>
<include>**/*.png</include>
<include>**/*.gif</include>
<include>**/*.xml</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
I also tried compiling with more output from Maven but I didn't see anything usefull for detecting the error.
Why doesn't the compiler show in which file the incomplete type is? How can I compile in such a way as to show what file had the error? Is it possible to validate an individual file to find such an error?
A simillair error has had a bug report here(https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&cad=rja&uact=8&ved=2ahUKEwix2evZmt3cAhXoNJoKHWQ7BXAQFjABegQICRAB&url=https%3A%2F%2Fnetbeans.org%2Fbugzilla%2Fshow_bug.cgi%3Fid%3D247421&usg=AOvVaw3ulnafW3ET1VWqw43wAEC0) where someone tried to combine Lists/arrays but had incorrect syntax. But is there a way too find out which file contains the error?
I found where the problem was.
I had a method declaration:
public synchronized static T[] <T> foo(...)
Instead of
public synchronized static <T> T[] foo(...)
Unbelivably frustrating that the compiler doesn't even say which source file it was.

when i use command `mvn test -Xlint:unchecked` . some error appear

[ERROR] No plugin found for prefix 'lint' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from
the repositories [local (C:\Users\Administrator\.m2\repository), alimaven (http://maven.aliyun.com/nexus/content/groups/public/)] -> [Help 1]
org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException: No plugin found for prefix 'lint' in the current project and in the plugin groups [org
.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (C:\Users\Administrator\.m2\repository), alimaven (http://maven.aliyu
n.com/nexus/content/groups/public/)]
at org.apache.maven.plugin.prefix.internal.DefaultPluginPrefixResolver.resolve(DefaultPluginPrefixResolver.java:93)
at org.apache.maven.lifecycle.internal.MojoDescriptorCreator.findPluginForPrefix(MojoDescriptorCreator.java:266)
at org.apache.maven.lifecycle.internal.MojoDescriptorCreator.getMojoDescriptor(MojoDescriptorCreator.java:220)
at org.apache.maven.lifecycle.internal.DefaultLifecycleTaskSegmentCalculator.calculateTaskSegments(DefaultLifecycleTaskSegmentCalculator.java:
103)
at org.apache.maven.lifecycle.internal.DefaultLifecycleTaskSegmentCalculator.calculateTaskSegments(DefaultLifecycleTaskSegmentCalculator.java:
83)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:89)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:993)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:345)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:191)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
Looks like your question is similar with Trouble with -Xlint:all and maven
or even
How to compile using -Xlint:unchecked in a Maven project?
Just add
<compilerArguments>
<Xlint:unchecked />
</compilerArguments>
or
<compilerArguments>-Xlint:unchecked</compilerArguments>
to your maven-compiler-plugin configuration
Firstly, the option is not working anymore
<compilerArguments> <Xlint:unchecked /> </compilerArguments>
So, to solve my problem, i found here this solution and change my plugin compiler
from
<artifactId>maven-compiler-plugin</artifactId>
to
<artifactId>maven-jar-plugin</artifactId>
Then my plugin looks like this
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
</plugin>
I'm not sure if this is the correct way, but works fine for me.

Why does Maven 3.3 not include 'javax.inject' but Maven 3.2 does?

My Maven build fails when using Maven 3.3.1 but is successful with Maven 3.2.2.
So far I have run /path/to/3.3.1/mvn clean compile -X and compared the output to the one produced by /path/to/3.2.2/mvn clean compile -X.
There was exactly one difference in the following block inside the maven-compiler-plugin / default-compile phase:
[DEBUG] Populating class realm plugin>org.apache.maven.plugins:maven-compiler-plugin:3.2
[DEBUG] Included: org.apache.maven.plugins:maven-compiler-plugin:jar:3.2
[DEBUG] Included: com.google.dagger:dagger-compiler:jar:2.0
[DEBUG] Included: com.google.dagger:dagger:jar:2.0
[DEBUG] Included: com.google.dagger:dagger-producers:jar:2.0-beta
[DEBUG] Included: com.google.guava:guava:jar:18.0
...
Difference: While Maven 3.2.2 printed [DEBUG] Included: javax.inject:javax.inject:jar:1, it is missing for Maven 3.3.1.
I don't know if this helps, but this is my effective build plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version> <!-- 3.3 respectively -->
<dependencies>
<dependency>
<groupId>com.google.dagger</groupId>
<artifactId>dagger-compiler</artifactId>
<version>2.0</version>
</dependency>
</dependencies>
<configuration>
<source>1.8</source>
<target>1.8</target>
<!-- workaround for http://jira.codehaus.org/browse/MCOMPILER-202 -->
<forceJavacCompilerUse>true</forceJavacCompilerUse>
</configuration>
</plugin>
What I don't understand: What exactly does the "Populating class realm plugin" do? Why is a jar missing, even though it has been identified as a dependency by both maven versions?
Edit: Build fails with this exception:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.2:compile (default-compile) on project ui: Compilation failure -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.2:compile (default-compile) on project ui: Compilation failure
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:913)
at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:129)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
... 20 more
A minimal example project is available on GitHub.
The full output of the failing command is available here.
The problem is not with the version of maven-compiler-plugin.
When you use the option forceJavacCompilerUse it would basically use javax.tool API implementation within your JDK.
Since you are using dagger-compiler, which is intern dependent on javax.inject, it should get pulled.
You can try adding [provided] scope for your dagger-compiler plugin dependency, this way you would be locking all the transitive dependencies.
Also make sure that you have added dagger
dependency in your runtime dependencies.
Please provide the some more details of exception-stack-trace and other related areas of your pom that would help visitors to narrow-down the problem and guide you quick!

JBehave Stories will not run as Embeddables

I have been attempting to run concurrent, multi-threaded stories using JBehave. They run correctly when using the embedder, but when running them as embeddables, they don't execute. When I change the source directories or the scope, I get a nullpointerException and when I comment them out, it builds successfully but does not find the class "My-ProgramStories.java." When I execute them using Maven with "mvn clean verify" this is what is returning (sorry for the ugly formatting):
[INFO] --- jbehave-maven-plugin:3.7.5:run-stories-as-embeddables (embeddable-stories) # program-test> ---
[INFO] Running stories as embeddables using embedder
Embedder[storyMapper=StoryMapper,storyRunner=StoryRunner,
embedderMonitor=MavenEmbedderMonitor,classLoader=EmbedderClassLoader[urls=[/Users//Documents/Repositories///target/test-classes/,
/Users//Documents/Repositories///target/classes,
groovy-all-1.8.4.jar],parent=ClassRealm[plugin>org.jbehave:jbehave-maven-plugin:3.7.5,
parent: sun.misc.Launcher$AppClassLoader#1729854]],embedderControls=
UnmodifiableEmbedderControls[EmbedderControls[batch=false,skip=false,generateViewAfterStories
true,ignoreFailureInStories=true,ignoreFailureInView=true,verboseFailures=false,
verboseFiltering=false,storyTimeoutInSecs=400,threads=4]],
embedderFailureStrategy=org.jbehave.core.embedder.Embedder$ThrowingRunningStoriesFailed#127c1
ee,configuration=org.jbehave.core.configuration.MostUsefulConfiguration#10c56cbd,candidateSte
s=[],stepsFactory=,metaFilters=[groovy: story_path ==~ /.*.story/],systemProperties
{},executorService=,executorServiceCreated=false,storyManager=]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:04.710s
[INFO] Finished at: Mon Jul 29 09:55:43 CDT 2013
[INFO] Final Memory: 60M/123M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.jbehave:jbehave-maven-plugin:3.7.5:run-stories-as
embeddables (embeddable-stories) on project : Failed to run stories as
embeddables: NullPointerException -> [Help 1]
This is how I have the JBehave Maven Plugin configured in the POM:
<properties>
<embeddables>**/My-ProgramStories.java</embeddables>
<ignore.failre.in.stories>true</ignore.failre.in.stories>
<meta.filter>groovy: story_path ==~ /.*.story/</meta.filter>
<threads>4</threads>
<story.timeout.in.secs>400</story.timeout.in.secs>
</properties>
...
<plugin>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-maven-plugin</artifactId>
<executions>
<execution>
<id>embeddable-stories</id>
<phase>integration-test</phase>
<configuration>
<includes>
<include>${embeddables}</include>
</includes>
<excludes>
<exclude>${exclude}</exclude>
</excludes>
<scope>test</scope>
<sourceDirectory>src/test/java</sourceDirectory>
<testSourceDirectory>src/test/resources</testSourceDirectory>
<skip>${skip}</skip>
<batch>false</batch>
<threads>${threads}</threads>
<storyTimeoutInSecs>${story.timeout.in.secs}</storyTimeoutInSecs>
<generateViewAfterStories>true</generateViewAfterStories>
<ignoreFailureInStories>
${ignore.failre.in.stories}
</ignoreFailureInStories>
<ignoreFailureInView>true</ignoreFailureInView>
<metaFilters>
<metaFilter>${meta.filter}</metaFilter>
</metaFilters>
</configuration>
<goals>
<goal>run-stories-as-embeddables</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>1.8.4</version>
</dependency>
</dependencies>
</plugin>
The structure of my story and test classes along with my story files as viewed through Eclipse is the following:
my-program-test
-->src/test/java
---->package1
------>My-ProgramSteps.java
------>My-ProgramStories.java
-->src/test/resources
---->package1
------>Story Files
Here is the stacktrace of the error:
[ERROR] Failed to execute goal org.jbehave:jbehave-maven-plugin:3.7.5:run-stories-as-embeddables (embeddable-stories) on project my-program: Failed to run stories as embeddables: NullPointerException -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.jbehave:jbehave-maven-plugin:3.7.5:run-stories-as-embeddables (embeddable-stories) on project my-program-test: Failed to run stories as embeddables
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
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.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoFailureException: Failed to run stories as embeddables
at org.jbehave.mojo.RunStoriesAsEmbeddables.execute(RunStoriesAsEmbeddables.java:20)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
... 19 more
Caused by: java.lang.NullPointerException
at org.codehaus.plexus.util.AbstractScanner.normalizePattern(AbstractScanner.java:327)
at org.codehaus.plexus.util.AbstractScanner.setExcludes(AbstractScanner.java:314)
at org.jbehave.core.io.StoryFinder.scanDirectory(StoryFinder.java:218)
at org.jbehave.core.io.StoryFinder.scan(StoryFinder.java:205)
at org.jbehave.core.io.StoryFinder.findClassNames(StoryFinder.java:61)
at org.jbehave.mojo.AbstractEmbedderMojo.classNames(AbstractEmbedderMojo.java:302)
at org.jbehave.mojo.RunStoriesAsEmbeddables.execute(RunStoriesAsEmbeddables.java:18)
... 21 more
Based on this
Caused by: java.lang.NullPointerException at
org.codehaus.plexus.util.AbstractScanner.normalizePattern(AbstractScanner.java:327) at
org.codehaus.plexus.util.AbstractScanner.setExcludes(AbstractScanner.java:314) at
Looks like your exclusion pattern configuration is broken. It would look like this:
<exclude>${exclude}</exclude>
is not defined in your properties. You could use effective-pom to confirm if all properties are properly expanded.

Unable to generate classes from JAXB in Maven environment

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.
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/ ).
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:
How do I create JAXB bindings for docbook
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>

Categories

Resources