Maven error Annotations are not supported in -source 1.3

The Error

Are you using annotations in your project?

If so, you will get this error if you try to do mvn compile or mvn install.

You may have also seen this if you are building your project on eclipse as well.

The solution

The default maven relies on JDK 1.3 for its building the project and you might be using a JDK above 1.3. Also, JDK 1.3 does not implement annotations.

The solution is to tell the maven the current non-1.3 JDK you are using on you pom.xml file.


<project>
.
.

  <build> 
    <plugins> 
      <plugin> 
        <artifactId>maven-compiler-plugin</artifactId> 
        <version>2.3.2</version> 
        <configuration> 
          <source>1.8</source> 
          <target>1.8</target> 
        </configuration> 
      </plugin> 
     </plugins> 
   </build> 
</project>

For the source and target you will provide your current JDK you are using.

Using mvn for creating and running a boilerplate minimal java application

It is almost a must to use mvn or any other build tool when dealing with java.

With mvn you can start a minimal simple all included java application and you run that too.. Just follow this. I will assume you are on linux or mac environment for this and also I am assuming you already have maven installed
Create a new folder and say mavenrocks

mkdir mavenrocks

Then add the following

mvn archetype:generate

What it does is, it will use a plugin to create a boilerplate application that holds basic src files along with standard directory structure.
if you do the listing on the created folder you will see:

.
./pom.xml
./src
./src/main
./src/main/java
./src/main/java/com
./src/main/java/com/gullele
./src/main/java/com/gullele/App.java
./src/test
./src/test/java
./src/test/java/com
./src/test/java/com/gullele
./src/test/java/com/gullele/AppTest.java
./target
./target/classes
./target/classes/com
./target/classes/com/gullele
./target/classes/com/gullele/App.class
./target/maven-status
./target/maven-status/maven-compiler-plugin
./target/maven-status/maven-compiler-plugin/compile
./target/maven-status/maven-compiler-plugin/compile/default-compile
./target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
./target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst

and to run it

mvn execute:java -Dexec.mainClass="com.gullele.App"

Eclipse Helios Classpath Error While Working With Maven

I usually work on both terminal and Eclipse for my development.
Like compiling, creating of the war using maven and usage of Tomcat from terminal, and for coding Eclipse.
But, there are times I might need Eclipse like for debugging. And I want to run Tomcat from Eclipse itself.

I was using Helios, the project runs great from terminal. But, when I try it from Eclipse, it is not publishing it b/c it can’t get the jars.
I have updated the maven dependency and everything seems there. Like when I am developing, Eclipse knows about the imported files and I had no problem.

In short, eclipse can’t import the jars from maven or eclipse class path error was there while reading from maven.

Solution to how to import dependencies from maven to eclipse or how to import jars from maven to eclipse

1. Make sure you have the M2E plugin on your eclipse. To check that:
1.a Go to Eclipse–Help–Install new software
1.b On the work with text box insert Sonatype – http://m2eclipse.sonatype.org/sites/m2e and follow the wizard
When you are done restart your eclipse

2. Check if M2_REPO class path variable is there. To check that:
2.a Window–Preferences–Java–Build Path–Classpath Variable in this there should be M2_REPO variable being set. If it is not set, click the New button and add the repository of your maven path there.

3. Go to Window–preference–Maven–User Settings and check if there are not any warnings there. Mostly on User Settings. If there is one, update with the correct one. I am on Ubuntu and mine is on /etc/maven2/settings.xml

Go to your terminal and issue mvn eclipse:eclipse
then, right click on your project–maven and hit update dependencies.
Here is the fun part::
right click on your project, select build path and look at the library tab your dependencies would be listed there with M2_REPO path at the beginning
Then, Click on Deployment Assesment, it is right above Java Build Path, Select Java Build Path Entries
Hit next, select all the listed ones and hit finish

Refresh the project, clear the tomcat and all should be fine.

This should fix your eclipse class not found exception only because it not reading from maven correctly problem

Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml maven on war

You might come across this error when building a web application on maven using the command

mvn war:war

This would be caused if maven is not aware of where the web.xml file is located.
If you follow the standard maven directory structure as

src/main/java
src/main/resources
src/main/webapp

You would have to copy the contents of WebContent [WEB-INF AND META-INF] to src/main/webapp folder – there maven would get it as expected.