How to Compile and Bulid a single file in maven project - eclipse

I am doing maven web project in JSf - Richfaces. I have been using "maven clean install" for clearing and build the project to create a war file. It is tedious work to build an entire project for a changes in a single file.
My Question is,
Is there any possibility to build a single java file instead of entire project.
Can we create a short cut or icon in eclipse to build the current project
(ie)"mvn clean install" to create war file

Maven uses incremental compilation i.e. it compiles only classes that changed on disk since the last build.
you can modify your pom.xml , so that "clean, install , deploy" happens automatically. Below is the code that you can append after customizing necessary fields
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.6.Final</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Related

Compilation error on antlr3 files in Eclipse 2022-09

Eclipse version: 2022-09
Eclipse m2e version: 2.0.4
antlr version: 3
antlr3-maven-plugin: 3.5.3
I have a project with a Logic.g file. Everything was working OK on a previous version of Eclipse (where I had installed an m2e antlr connector), meaning the file would be converted to target/generated-sources/antlr3 (LogicLexer.java and LogicParser.java), and somehow be picked up by Eclipse and compile a Logic.tokens file in target, and the LogicLexer.class and LogicParser.class within target.
In Eclipse 2022-09 however, my test classes that use either LogicLexer or LogicParser yield a compilation error in Errors "cannot be resolved to a type".
It's just a problem in Eclipse (nothing changed in the code, and a maven verify works correctly).
The tokens file and the .class are being generated as long as I have the lifecycleMappingMetadata configured (see snippet below).
Question: How can I make the Eclipse project see these compiled classes and remove the compilation errors?
<build>
<plugins>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr3-maven-plugin</artifactId>
<version>3.5.3</version>
<executions>
<execution>
<goals>
<goal>antlr</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings
only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.antlr</groupId>
<artifactId>antlr3-maven-plugin</artifactId>
<versionRange>[3.5.3,)</versionRange>
<goals>
<goal>antlr</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>true</runOnIncremental>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>

ajc on Maven command line, but not in Eclipse in order to keep Lombok working

After successfully following this HowTo to integrate Lombok and AspectJ in a Maven build, my code doesn't compile anymore in eclipse.
There are a lot of errors everywhere due to absence of getter/setter/constructors normally generated by Lombok.
My goal is to be able to use eclipse to develop using Lombok, and after that using a mvn clean install on command line in order to build.
I tried to skip AspectJ weaving in eclipse, but without success.
Here is the profile I used to skip AspectJ:
<profile>
<id>noAspectJ</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<executions>
<execution>
<id>process-classes</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerVersion>1.7</compilerVersion>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</profile>
The best solution I found was to remove the AspectJ plugin from my Eclipse, since it don't need it there.
This way I could also avoid using a profile.
But this could probably lead to some problem if I used the JUnit tests in eclipse.

What better way to include external jars into a signed jar used by an applet?

I have an applet that uses several external libs. The project requires the applet JAR is signed because I perform disk operations. Another requirement is that all libs are included in the applet jar . My first attempt working this way was to include all the JARs of the libraries in a local directory of the Eclipse project and include them in the Eclipse project. After that I exported the entire project as a non-executable JAR, getting run most libs. But some libraries are still not referenced and I can not run my application via applet completely. Is there any more appropriate way to use libs inside a signed applet JAR?
If you are using maven then you can extract all classes needed. The maven plugin will do this for you. It can also sign it if you have an jks file. Here is some setup for maven.
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.1</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>attached</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
<configuration>
<keystore>${basedir}/the jks.jks</keystore>
<alias>the alias</alias>
<storepass>the store pass</storepass>
<signedjar>${project.build.directory}/signed/${project.build.finalName}.jar</signedjar>
<verify>true</verify>
<jarPath>${project.build.directory}/${project.build.finalName}-jar-with-dependencies.${project.packaging}</jarPath>
</configuration>
</plugin>
</plugins>

Is there any way to execute many maven build one after the other in Eclipse?

I work on several project which I often have to make maven-install on them.
Is there a way to execute many maven build one after the other on many projects ?
I hope i'm understandable.
Thanks for help
I was too looking for that.
But didn't get satisfied on Creating just a new main maven project and
add all other projects to build as its modules project.
This way I could trigger all the projects builds by triggering just main project build.
But still, that wasn't digestable.
Well, you can script that and use the -f switch of maven to specify which pom to build one after the other...
If you want to stick with maven, you can make a dedicated pom for invoking the sequence of your build by using the maven exec plugin. But this results a naaasty pom. Use it as last resort, because plugins should be used only once in one phase of the maven lifecycle. In certain cases it might be handy, e.g. you want to be able to run your build on different platforms and don't want to script with python, etc..):
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<executable>mvn</executable>
<arguments>
<argument>-DskipTests=true</argument>
<argument>-f</argument>
<argument>${basedir}/relative/path/to/other/module/pom.xml</argument>
<argument>clean</argument>
<argument>install</argument>
</arguments>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<executable>mvn</executable>
<arguments>
<argument>-DskipTests=true</argument>
<argument>-f</argument>
<argument>${basedir}/relative/path/to/some/other/module/pom.xml</argument>
<argument>clean</argument>
<argument>install</argument>
</arguments>
</configuration>
</plugin>
</plugins>
<build>
<pluginManagement>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
<pluginManagement>

Maven Javadoc - Unable to generate Javadoc

I have the following dependency and build in my pom file. I'm able to manually create the javadoc with a Maven command. I can also succesfully perform a build. The output doesn't mention javadoc at all. I've also tried leaving out the output directory paths. POM File
Dependency section:
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8</version>
</dependency>
and then the build section:
<build>
<finalName>D</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8</version>
<configuration>
<outputDirectory>${project.build.directory}/javadoc</outputDirectory>
<reportOutputDirectory>${project.reporting.outputDirectory}/javadoc</reportOutputDirectory>
<version>2.8</version>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
The Maven Javadoc plugin doesn't run by default and needs to be bound to one of the default Maven lifecycle phases.
Here's how I would write the plugin's configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8</version>
<configuration>
<outputDirectory>${project.build.directory}/javadoc</outputDirectory>
<reportOutputDirectory>${project.reporting.outputDirectory}/javadoc</reportOutputDirectory>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<phase>site</phase>
<goals>
<goal>aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
Notice how I added an extra phase element to the execution. This will bind it to the "site" goal so that javadocs are generated when you run mvn site. Check Introduction to the Build Lifecycle if you want one of the default Java build phases.
Also note that I ditched the version parameter; by default, it should use your POM's version anyway.