Maven project not building in parent - java

Running $mvn clean install works when I'm running from the folder containing the pom but when I go up a folder level and run the same command, I get the following error:
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building xsdtools 4.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # xsdtools ---
[INFO] Deleting /home/myUser/Development/gitRepo/xxx_project/project/xsdtoolFolder/target
[INFO]
[INFO] --- maven-enforcer-plugin:1.1:enforce (enforce-versions) # xsdtools ---
[INFO]
[INFO] --- jaxb2-maven-plugin:2.1:xjc (xjc) # xsdtools ---
[INFO] Adding 'extension' flag to XJC arguments, since the 'generateEpisode' argument is given. (XJCs 'episode' argument requires that the 'extension' argument is provided).
[INFO] Ignored given or default xjbSources [/home/myUser/Development/gitRepo/xxx_project/project/xsdtoolFolder/src/main/xjb], since it is not an existent file or directory.
[ERROR] null [-1,-1]
java.io.FileNotFoundException: /home/myUser/Development/gitRepo/xxx_project/project/src/main/xsd/MyProjectV3.xsd (No such file or directory)
at com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory.newSchema(XMLSchemaFactory.java:232)
The pom file has the following:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- The package of your generated sources -->
<sources>
<source>src/main/xsd/MyProjectV3.xsd</source>
</sources>
</configuration>
</plugin>
</plugins>
</build>
and my file structure is
xxx_project
|
-pom.xml
-project
|
-pom.xml
-src
|
-main
|
-xsd
|
-MyProjectV3.xsd
How do I make the build successful regardless of the directory I'm running from?

Related

How do we set/modify the name for a specific dependency defined in pom.xml for a Java project?

Right now, the name is set to 'name + version'. I need to exclude the version from the final name.
Eg - For
<dependency>
<groupId>group-a</groupId>
<artifactId>artifact-b</artifactId>
<version>1.0</version>
</dependency>
I am seeing artifact-b-1.0.jar getting generated in my build, but I want it named artifact-b.jar so that I need need to alter all the scripts using the jar every time the version changes.
During build, your jar is generated to target. You can change the name for target using the finalName parameter. If you use install, the artifact is installed to the local repository (you cannot influence the name in the local repository). If you do deploy ,the artifact is deployed to a remote repository (there you cannot also not influence the name).
You can do like this:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>package.class.main.Method</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>${project.artifactId}</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</plugin>
</plugins>
</build>
You can use the install-file goal of the Maven Install Plugin:
<groupId>group-a</groupId>
<artifactId>artifact-b</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>3.0.0-M1</version>
<executions>
<execution>
<id>install-file-${project.artifactId}</id>
<goals>
<goal>install-file</goal>
</goals>
<phase>install</phase>
<configuration>
<file>${project.build.directory}/${project.build.finalName}.jar</file>
<artifactId>artifact</artifactId>
<version>b</version>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
mvn install output:
[INFO] ...
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # so58011949 ---
[INFO] Building jar: ...\target\so58011949-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:3.0.0-M1:install (default-install) # artifact-b ---
[INFO] Installing ...\target\artifact-b-0.0.1-SNAPSHOT.jar
to ...\.m2\repository\group-a\artifact-b\0.0.1-SNAPSHOT\artifact-b-0.0.1-SNAPSHOT.jar
[INFO] Installing ...\pom.xml
to ...\.m2\repository\group-a\artifact-b\0.0.1-SNAPSHOT\artifact-b-0.0.1-SNAPSHOT.pom
[INFO]
[INFO] --- maven-install-plugin:3.0.0-M1:install-file (install-file-artifact-b) # artifact-b ---
[INFO] Installing ...\target\artifact-b-0.0.1-SNAPSHOT.jar
to ...\.m2\repository\group-a\artifact\b\artifact-b.jar
[INFO] Installing ...\AppData\Local\Temp\artifact-b-0.0.1-SNAPSHOT7551062015093608214.pom
to ...\.m2\repository\group-a\artifact\b\artifact-b.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] ...
Local repository:
|
+- group-a
| +- artifact
| +- b
| +- artifact-b.jar
| +- artifact-b.pom
| +- artifact-b
| +- 0.0.1-SNAPSHOT
| +- artifact-b-0.0.1-SNAPSHOT.jar
| +- artifact-b-0.0.1-SNAPSHOT.pom
|

Unable to create java classes using codehaus.mojo jaxb2-maven-plugin

I have a spring based web application in which I am trying to consume a SOAP service. I am using jaxb2-maven-plugin(org.codehaus.mojo) for that. However I see an empty jaxb2 folder which is crated under target and I dont see any java classes in it. I have the wsdl placed correctly under the resources folder itself.
Below is the plugin config created in pom.xml
<build>
<finalName>${project.artifactId}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/main/java/com/xyz/rap/service/impl/wsdl</directory>
<targetPath>wsdl</targetPath>
</resource>
<resource>
<directory>src/main/config</directory>
<targetPath>config</targetPath>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- Package to store the generated file -->
<packageName>com.xxx.gen.retail.abc</packageName>
<!-- Treat the input as WSDL -->
<wsdl>true</wsdl>
<!-- Input is not XML schema -->
<xmlschema>false</xmlschema>
<!-- The location of the WSDL file -->
<schemaDirectory>${project.basedir}/src/main/resources</schemaDirectory>
<!-- The WSDL file that you saved earlier -->
<schemaFiles>gene.wsdl</schemaFiles>
<!-- Don't clear output directory on each run -->
<clearOutputDir>false</clearOutputDir>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<!-- or whatever version you use -->
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Below is the log when I run "maven install"
[INFO] Building rap-web Maven Webapp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
**[INFO] --- jaxb2-maven-plugin:1.6:xjc (xjc) # rap-web ---
[INFO] Generating source...
[WARNING] No encoding specified; default platform encoding will be used for generated sources.
[INFO] parsing a schema...
[INFO] compiling a schema...
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # rap-web ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 15 resources
[INFO] Copying 3 resources to wsdl
[INFO] Copying 1 resource to config
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) # rap-web ---
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 50 source files to C:\Users\xx67047\DSA-GIT-Projects\10.22.17-dsa-rap-services\rap-web\target\classes**
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # rap-web ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\xx67047\DSA-GIT-Projects\10.22.17-dsa-rap-services\rap-web\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) # rap-web ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # rap-web ---
It says Parsing and compiling the schema in logs but I dont see any java classes getting created in the logs and I see an empty jaxb2 folder and an other empty generated-sources folder getting created. Please refer below image for that:
jaxb2-maven-plugin will create classes by default into target/generated-sources/jaxb. if you are stil not getting classes into target folder then If you are using Eclipse, you can add this folder into your project build path: right-clicking on project and selecting "Build Path > Use Source Folder.
then you need to run mvn clean install it will clean or delete the target folder and regenerate everything.
Try the version 2.2 of the codehaus. Keep in mind that you will need to change your xml a bit since there is a difference between 1.x and 2.x.
Having said that I would like to tell you that I'm having a similar issue. But it could be caused by something else. I'm using IntelliJ and it's generating empty jaxb folder under the /target/generated-sources/.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<sources>
<source>/src/main/resources/xsd/</source>
</sources>
<outputDirectory>${project.basedir}/target/generated-sources/jaxb</outputDirectory>
<clearOutputDir>false</clearOutputDir>
</configuration>
</plugin>

Jar not attaching to new executable jar

I have a java/maven project that runs some database stuff perfectly (classpath is working great). I use a proprietary database jar in order to connect to the database. When I go to package up my software into a shaded jar the proprietary jar isn't referenced. When I check the log files I see this error:
Exception: java.lang.ClassNotFoundException: com.sybase.jdbc4.jdbc.SybDriver
I'm trying to put everything into a shaded jar using Maven. Is there something that I'm not doing? Why is the database jar not working in my new shaded jar?
Adding the shade plugin configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>package.class</mainClass>
</transformer>
</transformers>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>launcher</shadedClassifierName>
</configuration>
</execution>
</executions>
</plugin>
I have followed the instructions about setting up a file repository since we don't have a corporate repository.
I created a folder at c:\my-repo and put the lone jconn4.jar file inside. I then added this to my pom.xml:
<repositories>
<repository>
<id>my-local-repo</id>
<url>file://${basedir}/my-repo</url>
</repository>
</repositories>
and
<dependency>
<groupId>company</groupId>
<artifactId>jconn4.jar</artifactId>
<version>16.0</version>
</dependency>
Finally, at a command prompt I ran the command:
$ mvn org.apache.maven.plugins:maven-install-plugin:2.3.1:install-file -Dfile=C:\my-repo\jconn4.jar -DgroupId=company -DartifactId=jconn4.jar -Dversion=16.0 -Dpackaging=jar -DlocalRepositoryPath=C:\my-repo
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building My_Project 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install-file (default-cli) # My_Project ---
[INFO] Installing C:\my-repo\jconn4.jar to C:\my-repo\company\jconn4.jar\16.0\jconn4.jar-16.0.jar
[INFO] Installing C:\Users\jsmith\AppData\Local\Temp\mvninstall7806841451724024532.pom to C:\my-repo\company\jconn4.jar\16.0\jconn4.jar-16.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.613 s
[INFO] Finished at: 2016-12-08T10:26:08-05:00
[INFO] Final Memory: 7M/245M
[INFO] ------------------------------------------------------------------------
That's all well and good but I keep getting this error in my pom.xml now "Missing artifact company:jconn4.jar:jar:16.0"
Have I implemented something incorrectly?

Why annotation processing run multiple times during maven build

I'm currently using java annotation processing to generate a lot of code (20 seconds), when I run mvn process-resources it will trigger apt only once however when I use mvn package, mvn jetty:run or mvn gwt:run apt been triggered again after war been packaged. Is there a way to force apt only run once?
I have a profile in my pom.xml
<profile>
<id>codegen</id>
<activation>
<activeByDefault>false</activeByDefault>
<file>
<exists>src/main/resources/META-INF</exists>
</file>
</activation>
<dependencies>
<dependency>
<groupId>com.regulationworks.core.code-gen</groupId>
<artifactId>executor</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>2.0.5</version>
<executions>
<execution>
<id>generate-jpa-metamodel</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<processors>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</processors>
<outputDirectory>${project.build.directory}/generated-sources/metamodel</outputDirectory>
</configuration>
</execution>
<execution>
<id>generate-gwt-jpa-proxies</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<processors>
<processor>org.hibernate.gwtmodelgen.GwtProxyModelEntityProcessor</processor>
</processors>
<outputDirectory>${project.build.directory}/generated-sources/entity-proxies</outputDirectory>
</configuration>
</execution>
<execution>
<id>code-gen-executor</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<processors>
<processor>com.regulationworks.core.gwt.codegen.CodeGenExecutor</processor>
</processors>
<options>
<generateRequestFactory>${core.codegen.requestfactory}</generateRequestFactory>
<generateMappingXml>${core.codegen.xmlmapping}</generateMappingXml>
<codegen.scaffold>${codegen.scaffold}</codegen.scaffold>
<codegen.scaffold.override>${codegen.scaffold.override}</codegen.scaffold.override>
<codegen.scaffold.classes>${codegen.scaffold.classes}</codegen.scaffold.classes>
<codegen.commands.class.name>${codegen.commands.class.name}</codegen.commands.class.name>
</options>
</configuration>
</execution>
<!--<execution>
<id>generate-gwt-rf</id>
<goals>
<goal>process</goal>
</goals>
<phase>process-classes</phase>
<configuration>
<processors>
<processor>com.google.web.bindery.requestfactory.apt.RfValidator</processor>
</processors>
<options>
<rootOverride>${core.codegen.rfvalidate}</rootOverride>
</options>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
</configuration>
</execution>-->
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<phase>process-classes</phase>
<configuration>
<id>VerifyRequestFactoryInterfaces</id>
<executable>java</executable>
<arguments>
<argument>-cp</argument>
<classpath />
<argument>com.google.web.bindery.requestfactory.apt.ValidationTool</argument>
<argument>${project.build.outputDirectory}</argument>
<argument>${core.codegen.rfvalidate}</argument>
</arguments>
<skip>${core.codegen.rfvalidate}</skip>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
and maven-source-plugin been configured to 'jar-no-fork' (this helped to remove one time when run normal mvn install)
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<executions>
<execution>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
here is output in console when run "mvn clean package gwt:run"
X:\workspace\Decision\decision-app>mvn clean package gwt:run
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building DecisionWorks App 2.0.2-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for org.opensaml:opensaml:jar:1.1b is missing, no dependency information available
[WARNING] The POM for net.sf.saxon:saxon-dom:jar:8.9 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[INFO]
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) # decision-app ---
[INFO] Deleting X:\workspace\Decision\decision-app\target
[INFO]
***********************************************************
This is where apt executed first time which look right
***********************************************************
[INFO] --- maven-processor-plugin:2.0.5:process (generate-jpa-metamodel) # decision-app ---
[INFO] Source directory: X:\workspace\Decision\decision-app\target\generated-sources\metamodel added
[INFO] javac option: -cp
[INFO] javac option: ...
[INFO] javac option: -proc:only
[INFO] javac option: -processor
[INFO] javac option: org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor
[INFO] javac option: -d
[INFO] javac option: X:\workspace\Decision\decision-app\target\classes
[INFO] javac option: -s
[INFO] javac option: X:\workspace\Decision\decision-app\target\generated-sources\metamodel
[INFO] diagnostic Note: Hibernate JPA 2 Static-Metamodel Generator 1.0.0.Final
[INFO]
[INFO] --- maven-processor-plugin:2.0.5:process (generate-gwt-jpa-proxies) # decision-app ---
[INFO] Source directory: X:\workspace\Decision\decision-app\target\generated-sources\entity-proxies added
[INFO] javac option: -cp
[INFO] javac option: ...
[INFO] javac option: -proc:only
[INFO] javac option: -processor
[INFO] javac option: org.hibernate.gwtmodelgen.GwtProxyModelEntityProcessor
[INFO] javac option: -d
[INFO] javac option: X:\workspace\Decision\decision-app\target\classes
[INFO] javac option: -s
[INFO] javac option: X:\workspace\Decision\decision-app\target\generated-sources\entity-proxies
[INFO] diagnostic Note: Hibernate JPA 2 Static-Metamodel Generator 3.7.0-SNAPSHOT
[INFO]
[INFO] --- maven-processor-plugin:2.0.5:process (code-gen-executor) # decision-app ---
[INFO] Source directory: X:\workspace\Decision\decision-app\target\generated-sources\apt added
[INFO] Adding compiler arg: -Acodegen.scaffold.override=true
[INFO] javac option: -cp
[INFO] javac option: ...
[INFO] javac option: -proc:only
[INFO] javac option: -Acodegen.scaffold.override=true
[INFO] javac option: -processor
[INFO] javac option: com.regulationworks.core.gwt.codegen.CodeGenExecutor
[INFO] javac option: -d
[INFO] javac option: X:\workspace\Decision\decision-app\target\classes
[INFO] javac option: -s
[INFO] javac option: X:\workspace\Decision\decision-app\target\generated-sources\apt
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) # decision-app ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 10 resources
[INFO] Copying 17 resources
[INFO] Copying 80 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) # decision-app ---
[INFO] Compiling 260 source files to X:\workspace\Decision\decision-app\target\classes
[INFO]
[INFO] --- exec-maven-plugin:1.2:exec (default) # decision-app ---
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) # decision-app ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 3 resources
[INFO] Copying 3 resources
[INFO] Copying 10 resources
[INFO] Copying 17 resources
[INFO] Copying 80 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) # decision-app ---
[INFO] Compiling 3 source files to X:\workspace\Decision\decision-app\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.9:test (default-test) # decision-app ---
[INFO] Surefire report directory: X:\workspace\Decision\decision-app\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
...
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.172 sec
Results :
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-war-plugin:2.1.1:war (default-war) # decision-app ---
[INFO] Packaging webapp
[INFO] Assembling webapp [decision-app] in [X:\workspace\Decision\decision-app\target\decision]
[INFO] Processing war project
[INFO] Copying webapp webResources [X:\workspace\Decision\decision-app\target] to [X:\workspace\Decision\decision-app\target\decision]
[INFO] Copying webapp webResources [X:\workspace\Decision\decision-app\src/main/webapp/WEB-INF] to [X:\workspace\Decision\decision-app\target\decision]
[INFO] Copying webapp resources [X:\workspace\Decision\decision-app\src\main\webapp]
[INFO] Processing overlay [ id com.regulationworks.core:document-cmis-plugin-config]
[INFO] Webapp assembled in [10118 msecs]
[INFO] Building war: X:\workspace\Decision\decision-app\target\decision.war
[WARNING] Warning: selected war files include a WEB-INF/web.xml which will be ignored
(webxml attribute is missing from war task, or ignoreWebxml attribute is specified as 'true')
[INFO]
[INFO] --- maven-source-plugin:2.1.2:jar-no-fork (default) # decision-app ---
[INFO]
[INFO] >>> gwt-maven-plugin:2.3.0:run (default-cli) # decision-app >>>
***********************************************************
This is where apt executed second time which is a waste of time
***********************************************************
[INFO]
[INFO] --- maven-processor-plugin:2.0.5:process (generate-jpa-metamodel) # decision-app ---
[INFO] Source directory: X:\workspace\Decision\decision-app\target\generated-sources\metamodel added
[INFO] javac option: -cp
[INFO] javac option: ...
[INFO] javac option: -proc:only
[INFO] javac option: -processor
[INFO] javac option: org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor
[INFO] javac option: -d
[INFO] javac option: X:\workspace\Decision\decision-app\target\classes
[INFO] javac option: -s
[INFO] javac option: X:\workspace\Decision\decision-app\target\generated-sources\metamodel
[INFO] diagnostic Note: Hibernate JPA 2 Static-Metamodel Generator 1.0.0.Final
[INFO]
[INFO] --- maven-processor-plugin:2.0.5:process (generate-gwt-jpa-proxies) # decision-app ---
[INFO] Source directory: X:\workspace\Decision\decision-app\target\generated-sources\entity-proxies added
[INFO] javac option: -cp
[INFO] javac option: ...
[INFO] javac option: -proc:only
[INFO] javac option: -processor
[INFO] javac option: org.hibernate.gwtmodelgen.GwtProxyModelEntityProcessor
[INFO] javac option: -d
[INFO] javac option: X:\workspace\Decision\decision-app\target\classes
[INFO] javac option: -s
[INFO] javac option: X:\workspace\Decision\decision-app\target\generated-sources\entity-proxies
[INFO] diagnostic Note: Hibernate JPA 2 Static-Metamodel Generator 3.7.0-SNAPSHOT
[INFO]
[INFO] --- maven-processor-plugin:2.0.5:process (code-gen-executor) # decision-app ---
[INFO] Source directory: X:\workspace\Decision\decision-app\target\generated-sources\apt added
[INFO] Adding compiler arg: -Acodegen.scaffold.override=true
[INFO] javac option: -cp
[INFO] javac option: ...
[INFO] javac option: -proc:only
[INFO] javac option: -Acodegen.scaffold.override=true
[INFO] javac option: -processor
[INFO] javac option: com.regulationworks.core.gwt.codegen.CodeGenExecutor
[INFO] javac option: -d
[INFO] javac option: X:\workspace\Decision\decision-app\target\classes
[INFO] javac option: -s
[INFO] javac option: X:\workspace\Decision\decision-app\target\generated-sources\apt
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) # decision-app ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 10 resources
[INFO] Copying 17 resources
[INFO] Copying 80 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) # decision-app ---
[INFO] Compiling 60 source files to X:\workspace\Decision\decision-app\target\classes
[INFO]
[INFO] --- exec-maven-plugin:1.2:exec (default) # decision-app ---
[INFO]
[INFO] <<< gwt-maven-plugin:2.3.0:run (default-cli) # decision-app <<<
[INFO]
[INFO] --- gwt-maven-plugin:2.3.0:run (default-cli) # decision-app ---
***********************************************************
finally be able to start the web app, 30 seconds wasted for second apt execution
***********************************************************
----------------------- solution -----------------------
add a "package" profile
<profile>
<id>package</id>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<packagingExcludes>WEB-INF/lib/*-sources.jar, WEB-INF/lib/gwt-user-*.jar</packagingExcludes>
<webResources>
<resource>
<directory>src/main/webapp/WEB-INF</directory>
<targetPath>WEB-INF</targetPath>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</webResources>
</configuration>
<executions>
<execution>
<id>explode-war</id>
<phase>compile</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
use "mvn clean gwt:run -Ppackage" instead of "mvn clean package gwt:run"
The command you executed is mvn clean package gwt:run. Maven executes the clean lifecycle (clean:clean goal by default). Then it executes package, which runs all goals bound to the package phase and all goals bound to previous phases (generate-sources, process-sources, process-resources, etc.). Finally, it executes the gwt:run goal. If you look at the documentation for the run goal there is one very important line:
Invokes the execution of the lifecycle phase process-classes prior to executing itself.
This means that Maven will run all goals bound to the process-classes phase and all earlier phases again. The apt plugin executions are bound to the generate-sources phase so they repeat, as do resources:resources, compiler:compile, and exec:exec as they are all bound to process-classes or before.
With that in mind: does mvn clean gwt:run work? I know that mvn clean jetty:run works as I expect without duplicating executions, but I've not used gwt before.

Maven: Java classes don't compile after Ant task

My project generates source code using the Rats! parser generator. Rats! doesn't have a Maven plugin that I'm aware of, so I'm trying to build the parser using an Ant Java
task, like so:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<configuration>
<tasks>
<mkdir dir="${project.build.directory}/generated-sources/main/java/" />
<java classpath="lib/xtc.jar" classname="xtc.parser.Rats">
<arg line="-in ${project.build.sourceDirectory}" />
<arg line="-out ${project.build.directory}/generated-sources/main/java/" />
<arg path="${project.build.sourceDirectory}/Dot.rats" />
</java>
</tasks>
<sourceRoot>
${project.build.directory}/generated-sources/main/java
</sourceRoot>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
The details of what Rats! does aren't important: the end result is that
the above generates Dot.java and places it in
target/generated-sources/main/java. It works fine.
The problem is that, with this plugin element in my pom.xml, none of
the Java files in the project get compiled.
I generated a project
using "mvn archetype:create -DgroupId=foo -DartifactId=bar" and added the
file src/main/java/Dot.rats:
module Dot;
public void Dot = "." !_ ;
(This is a grammar that accepts only files with a single dot.)
If I run "mvn compile" without the plugin element, I get:
$ mvn compile
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building bar
[INFO] task-segment: [compile]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Compiling 1 source file to
/home/chris/src/tests/maven/project1/bar/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Wed Jul 01 18:57:08 EDT 2009
[INFO] Final Memory: 6M/67M
[INFO] ------------------------------------------------------------------------
Where the one Java file being compiled is src/main/java/foo/App.java, a Java class created by the archetype (i.e., not a generated source file).
If I do "mvn clean" then add the plugin element invoking Rats!, I get:
$ mvn compile
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building bar
[INFO] task-segment: [compile]
[INFO] ------------------------------------------------------------------------
[INFO] [antrun:run {execution: default}]
[INFO] Executing tasks
[mkdir] Created dir:
/home/chris/src/tests/maven/project1/bar/target/generated-sources/main/java
Rats! Parser Generator, v. 1.14.2, (C) 2004-2008 Robert Grimm
Processing /home/chris/src/tests/maven/project1/bar/src/main/java/Dot.rats ...
I.e., Maven is running Rats! (which is not failing, AFAICT) but not compiling any Java classes, not even the pre-existing class App.java. After the run, I have target/generated-sources/main/java/Dot.java but no target/classes.
I've tried other kinds of Ant tasks and they don't interfere with Java
compilation. For example, if I replace the task element above with an
echo task
<tasks>
<mkdir dir="${project.build.directory}/generated-sources/main/java/" />
<echo file="${project.build.directory}/generated-sources/main/java/Dot.java">
public class Dot { }
</echo>
</tasks>
I get
$ mvn compile
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building bar
[INFO] task-segment: [compile]
[INFO] ------------------------------------------------------------------------
[INFO] [antrun:run {execution: default}]
[INFO] Executing tasks
[INFO] Executed tasks
[INFO] Registering compile source root
/home/chris/src/tests/maven/project1/bar/target/generated-sources/main/java
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Compiling 2 source files to
/home/chris/src/tests/maven/project1/bar/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Wed Jul 01 19:03:34 EDT 2009
[INFO] Final Memory: 7M/79M
[INFO] ------------------------------------------------------------------------
Obviously there's something I'm not understanding about how Maven
executes the java task. Is there something simple that I'm doing
wrong? Is there an alternative way to accomplish this task that I
should try (perhaps a more "Maven-native" way)?
[UPDATE] Funny story. I tried replacing the Ant task with a Maven plugin, by writing a RatsMojo class that invokes xtc.parser.Rats directly and replacing the plugin element above with
<plugin>
<groupId>edu.nyu.xtc</groupId>
<artifactId>maven-xtc-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>rats</goal>
</goals>
<configuration>
<inputDirectory>${project.build.sourceDirectory}</inputDirectory>
<outputDirectory> ${project.build.directory}/generated-sources/main/java</outputDirectory>
<grammarFile>${project.build.sourceDirectory}/Dot.rats</grammarFile>
</configuration>
</execution>
</executions>
</plugin>
It does the exact same thing: it runs Rats! then terminates without compiling any of the Java files in the project.
The problem seems to be that Rats! calls System.exit() (or similar), terminating the JVM. I would have thought that Ant would wrap this (the java task is copied over from a build.xml and it doesn't terminate the Ant build), but the following works by forcing the Rats! process into a separate JVM:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<argument>${basedir}/lib/xtc.jar</argument>
<argument>xtc.parser.Rats</argument>
<argument>-in</argument>
<argument>${project.build.sourceDirectory}</argument>
<argument>-out</argument>
<argument>${project.build.directory}/generated-sources/main/java/</argument>
<argument>${project.build.sourceDirectory}/Dot.rats</argument>
</arguments>
</configuration>
</plugin>
or, just add fork="true" to the java task in the antrun plugin.
You need to add the new directory to the maven source directories. It can be done using the buildhelper-maven-plugin. Add this to your pom:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/main/java/</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Categories