Eclipse: Issue with apt-maven-plugin generating an "empty" class - eclipse

I have a project that uses the com.mysema.maven:apt-maven-plugin:1.0.4 to automatically generate classes used for query-DSL.
The project builds fine with maven executed on the command-line.
However, when I build the same project within Eclipse the "Q-classes" (so-called because they all have a name prefixed with 'Q') are generated except one of them:
Class QZHStRegisterJPBaseOptimisticLockingEntity is generated as "empty" file.
Oddly, that generated source file is not completely empty but it contains a package name and two imports but nothing more, i.e. it contains no class declaration and thus that class (which is referred to by many other classes) does not exists leading to tons of compile errors.
This is how the generated source file looks like:
package ch.zh.ksta.zhstregisterjp.dom.base;
import static com.mysema.query.types.PathMetadataFactory.*;
import com.mysema.query.types.path.*;
Does anyone have any idea why this is not working and what could cause the apt-maven-plugin to emit such a "half-baken" incomplete file???
Just in case: the plugin does get executed. I have defined a Maven lifecycle-mapping in eclipse like so:
...
<pluginExecution>
<pluginExecutionFilter>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId> <!-- the new artifactId -->
<versionRange>[1.0.4,)</versionRange>
<goals>
<goal>generate-sources</goal>
<goal>process</goal>
<goal>test-process</goal>
</goals>
</pluginExecutionFilter>
<action>
<!-- ->
<ignore/>
<!- -->
<execute>
<runOnConfiguration>true</runOnConfiguration>
<runOnIncremental>true</runOnIncremental>
</execute>
</action>
</pluginExecution>
...
Also, the Q-classes are generated fine during the build, except for that single "empty" one mentioned.

Related

How to make an executable JAR files

How do you build an executable JAR file in Netbeans 12.6? I realize this question is asked frequently but none of the other solutions previously posted here work on the latest version of Netbeans. All I ever get is "no main manifest attribute". Amazing to me that such a simple thing does not just work out-of-the-box. Getting Netbeans set up has been harder to learn than Java itself!
When you set the project’s main class, you ensure that the main class is be designated in the manifest. To set the project’s main class:
Right-click the project’s node and choose Properties.
Select the Run category and enter projectname.className in the Main Class field.
Click OK to close the Project Properties dialog box.
https://netbeans.apache.org/kb/docs/java/javase-deploy.html
Here is what worked for me. For Maven, you need to update the POM.xml file. Netbeans does not work out of the box in version 12.6 like older versions. I'm sure they added more functionality but it no longer just works. It maybe similar for Gradle. Add this above ~ < /project> in your file. Change your class name to your's. (My class was called main).
<build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.mypackage.MyClass</mainClass>
</manifest>
</archive>
</configuration>
</plugin>

How to run annotation processor in eclipse on save

Currently I generate files with an annotation processor in eclipse for a project by
Right click on project > Run As > Maven Clean
Right click on project > Run As > Maven install
This is quite time consuming. How do I set up eclipse to make it run the annotation processor on save?
I have the "Build Automatically" feature set but it seems to ignore the annotation processors. BTW I am using m2e apt plugin with "Automatically configure JDT APT activated".
I have annotation processing working in Eclipse for some of my projects; for me, it IS working on save, and I don't have to mvn install (and it works differently than Maven, as Eclipse runs its own compiler).
I'm also using m2e-apt plugin for this.
As noted above, Eclipse runs its own compiler; that means that its output can differ slightly than Maven's (when you "Right click on project > Run As > Maven Clean / Install" you're invoking Maven, not Eclipse). I'm mentioning this because it is entirely possible that your processors have a problem and work in Maven but not in Eclipse (although most of the time they do produce the same output; I've seen some differences, but very small). I'd keep an eye on Eclipse's error log if I were you (because that's where annotation processing errors are written).
So here is what I suggest:
Post A picture with your Maven / Annotation Processing settings in Eclipse (even though you do seem to have the correct option activated).
Post a picture with Java/Compiler settings (there is a checkmark in there that needs to be activated; it doesn't work without).
Posting your pom.xml would, strangely, be helpful. Especially if you have custom configuration for maven-compiler-plugin. Some of that config is interpreted by m2e-apt, such as compiler arguments.
Look for a file called .factorypath. That's where m2e-apt keeps the list of jars that it scans for annotation processing (you'll find all the jars of your project in there, even though they don't actually contain processors; that is, unless your maven-compiler-plugin is configured as such to only consider a specific list of processors). If the jar containing your processor is not in .factorypath, it won't work.
Last but not least, there is another thing that can cause problems. If the project containing the actual annotation processor (so NOT the "client") is in the same workspace as the "client" project, then m2e-apt will simply ignore your annotation processor; I don't know why. Closing your annotation processor project would be enough in this case (you don't have to delete it from workspace).
Edit: Forgot to say that if you do run your annotation processing via Maven (and you're invoking Maven just to process annotations), then mvn compile should be enough. Also, you don't need to run it separately (first mvn clean then mvn compile). You can run it in one shot with mvn clean compile; it is supposed to have the exact same effect.
Make sure your Java project settings (accessible with right-click on project > Java compiler > Annotation processors) do enable annotation processing and that the settings match your expections.
For Maven project, m2e is supposed to configure those settings properly according to the pom.xml content. However, this is not working smoothly for all Maven plugins (some will be supported "out-of-the-box", some others will require a specific plugin...).
I think you need a trigger to run Maven goal, So:
You have to add a valid maven lifecycle action
Example for a jar which is automatically deployed locally by maven install plugin:
<build>
<!-- ... -->
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<versionRange>[2.0,)</versionRange>
<goals>
<goal>jar</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnConfiguration>true</runOnConfiguration>
<runOnIncremental>true</runOnIncremental>
</execute>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<versionRange>[2.5.0,)</versionRange>
<goals>
<goal>install</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnConfiguration>true</runOnConfiguration>
<runOnIncremental>true</runOnIncremental>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
Hint: relates to Maven Project Builder is invoked every time I change a source file (GWT) and as a warning: install typically includes tests if you have included them in your normal maven build cycle

Check the inheritance chain from module; it may not be inheriting a required module or a module may not be adding its source path entries properly

I want to create a gwt maven project with multiple gwt modules. some of them are just utility modules means they have no entry point. Basically I have already a gwt project with multiple gwt modules in it and I have converted it to maven but while compilation its giving me following exception :
[ERROR] Unable to find type
'in.appops.showcase.web.gwt.uploadservice.client.UploadService' [INFO]
[ERROR] Hint: Previous compiler errors may have made this type
unavailable [INFO] [ERROR] Hint: Check the inheritance chain
from your module; it may not be inheriting a required module or a
module may not be adding its source path entries properly
My project has core and dispath modules which are utility modules without entry point and other uploadservice module which has entry point which is inheriting the core module .
So I put core.gwt.xml ,dispatch.get.xml in their packages i.e in src/main/java itself and uploadservice.gwt.xml in resources folder of maven.
also in pom.xml I am providing the modules to compile:
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.4.0</version>
<goals>
<goal>clean</goal>
<goal>resources</goal>
<goal>compile</goal>
<goal>i18n</goal>
<goal>generateAsync</goal>
</goals>
<configuration>
<runTarget>Index.html</runTarget>
<hostedWebapp>${webappDirectory}</hostedWebapp>
<modules>
<!-- <module>platform.bindings.web.gwt.dispatch.Dispatch</module>
<module>platform.core.Core</module> -->
<module>showcase.web.gwt.addressbook.AddressBook</module>
<module>showcase.web.gwt.uploadservice.UploadService</module>
</modules>
</configuration>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
can anybody help me to get out of this exception. Is it neccessary that I need to provide the order to compile the modules or anything else?
Note 1 -
When using gwt standard approach your folder structure
src/main/java/showcase/web/gwt/yourmodule/yourmodule.gwt.xml
src/main/java/showcase/web/gwt/yourmodule/client
src/main/java/showcase/web/gwt/yourmodule/public
Your pom references
<module>showcase.web.gwt.addressbook.AddressBook</module>
<module>showcase.web.gwt.uploadservice.UploadService</module>
Your .gwt.xml file location
src/main/java/showcase/web/gwt/addressbook/AddressBook.gwt.xml
src/main/java/showcase/web/gwt/uploadservice/UploadService.gwt.xml
Note 2 - <lifecycleMappingMetadata> is for your m2e = maven eclipse plugin. For clear example of GWT MAVEN POM example - http://code.google.com/p/google-web-toolkit/source/browse/trunk/samples/validation/pom.xml
Note 3 - Exactly follow the extremely simple example of gwt maven sample project - http://code.google.com/p/google-web-toolkit/source/browse/trunk/samples/validation/
DO NOT CHANGE FOLDER LOCATION. *FOLLOW THE NAMING CONVENTION.* even folder names like public, client are picked by "name" in GWT.
If this error occurs upon loading the entry point, you may need to change the tags in your *.gwt.xml file.
After changing my package structure, I was able to successfully fix the error, "Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly".
In your .gwt.xml file, find the source tags near the bottom of the file.
revert to an earlier working commit, or open a known working project
take note of the pattern that the working source tags follow relative to the package structure of your working project.
roll forward to the broken commit
modify your source tag(s) to correspond to the current package structure, following the same pattern.
In addition, you should check to make sure you have the appropriate inherits tags in your .gwt.xml file. For example, you will get a similar error if you attempt to use SmartGWT without the tag inherits name="com.smartgwt.SmartGWt"
Your UploadService.gwt.xml file should be in src/main/resources/in/appops/showcase/web/gwt/uploadservice. Others GWT module descriptors should be in their packages as well.

AspectJ Maven Plugin <weaveDependency>

I am trying to use aspectj maven plugin in our project that has multiple modules. Following the instructions given in this link http://mojo.codehaus.org/aspectj-maven-plugin/weaveJars.html
I am using #Aspectj annotation. My aspect is in a separate maven module called
artifactId - consumer
And the class whose method i want to intercept or advice is in
artifactId - producer
I have added the following configuration in the pom file of the consumer module:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<showWeaveInfo>true</showWeaveInfo>
<weaveDependencies>
<weaveDependency>
<groupId>com.home.demo</groupId>
<artifactId>producer</artifactId>
</weaveDependency>
</weaveDependencies>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
Also added "producer" as a dependency in the same pom file.
When i am doing mvn clean install for the consumer module the following information comes in the console.
[INFO] [aspectj:compile {execution: default}]
[INFO] Join point 'method-execution(void com.home.demo.producer.messaging.MomServiceEndpointListener.handle(com.home.messaging.service.MessageContext, com.home.messaging.service.MessageContext))' in
Type 'com.home.demo.producer.messaging.MomServiceEndpointListener' (MomServiceEndpointListener.java:21) advised by before advice from 'com.home.demo.ods.app.OdsConsumer' (OdsConsumer.java:38)
But while executing the application, it's not working. The aspect is not getting invoked.
I am not able to understand whether i am missing something.
Also i am having confusion whether the plugin configuration shown above should be in which module consumer(where my aspects are) or producer.
The problem is that weaveDependencies act like sources only.
Your consumer module takes original "sources" from weaveDependencies (producer), weaves them with aspects and put weaved classes into consumer(!!!) target/classes.
Therefore, producer artifact never knows about aspects and you use it unchanged.
You have to re-build a producer jar using classes from consumer/target/classes.
I don't think it's convenient, so i left my attempts to use this plugin in this way.
Also, several weaveDependencies will be merged into one scrap-heap of classes.
You better try Aspects from your external jar dependency and plugin config that is built into producer.

deploying a maven project

I have a maven project and I'd like to create a distribution of it with the dependencies. I've tried the maven-assembly-plugin and built the jar with dependencies, but that unpacked all of the jars and repackaged them all into a big, single jar. What I'd like is something like my jar file and a lib folder that has all of the dependencies. Then when I run it, I could run "java -cp lib/* my.package.MainClass".
What's the best way to go about doing this with maven? Or the recommended way to deploy?
thanks,
Jeff
I have used the Maven assembly just for that in my project.
First enable your plugin in your POM and call your assembly config :
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<!--I recommend 2.1 as later versions have a bug that may
Duplicate files in your archive
-->
<version>2.1</version>
<!--Executes the packaging along with the mvn package phase
-->
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>attached</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptors>
<!--Relative path to your descriptor -->
<descriptor>src/main/assembly/package.xml
</descriptor>
</descriptors>
</configuration>
</plugin>
Then in your descriptor you can decide how you want your layout to be before you package the whole thing
<assembly>
<!-- this will create an extra resource project-1.1.1-package.zip, you can
choose jar as well in the format-->
<id>package</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<!-- Insert here extra files as configs or, batch files, resources, docs etc-->
<fileSets>
<fileSet>
<directory>src/main/assembly/files</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>**/conf/*.*</include>
<include>**/doc/*.*</include>
</includes>
</fileSet>
<!-- I like to integrate the jre as well... simplifies my deployement -->
<fileSet>
<directory>target/jre</directory>
<outputDirectory>/jre</outputDirectory>
</fileSet>
</fileSets>
<!-- This will scrub your dependencies and add them to your lib folder, I excluded
Test stuff as it is not needed, could have declared the resource as a test
only phase as well would not have had to exclude it here
-->
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<excludes>
<exclude>junit:junit</exclude>
</excludes>
</dependencySet>
</dependencySets>
</assembly>
This will create a zip file with the layout you have specified in your output directory config, package the whole thing as a zip file (you can choose zip, jar, war ...) and deploy it in my repository with the rest.
I skipped bits and pieces to make it simpler but my package expands to include batch files, dlls, config, doc and the JRE so everything needed is in the same zip... all is needed to run the thing is extract and click start.bat !
I could also probably make it in to a jar properly formatted with METADATA and just double click the jar itself to start it all, I did not need or have time to toy around this option but you may try it as well.
Beware of versions above 2.1 of the assembly plugin, it will create duplicate entries if your directives enable it to find the same file in different locations, this will give you a lib folder with the same jars repeating twice. not very dangerous as unzipping will collapse them but still annoying to have the unzip ask you if you want to overwrite files. Plus the fact that you do not know which won if somehow they turned out to be different in content.
Maven is great but I find that it is sometimes frustrating to get it working, Plus documentation can sometimes be hard to find and use. However, used appropriately it will save you tons of time.
good luck
See:
http://maven.apache.org/shared/maven-archiver/index.html
You should be able to use the maven-jar plugin to package up an archive, specify the main class to execute along with the classpath. It can generate a manifest file for you for your project.
http://maven.apache.org/shared/maven-archiver/examples/classpath.html#Prefix