Category Archives: Maven

[Solved] Maven “class file has wrong version X, should be Y”


The java.lang.UnsupportedClassVersionError is a sub-class of LinkageError and ClassFormatError. The JVM (Java Virtual Machine) throw this error when try to read a file but Major and Minor Java version are not supported.

This Java Major and Minor class error occurred while running through IDE eclipse/STS or any because you JAVA_HOME or path or IDE Build Path is configured with different version of Java (JDK/JRE) however your code is compiled with different version of IDE. or Maven pom.xml is configured with different java version while running the program over different JDK/JRE which is not match with Major and Minor version supported.

In further post you will get to know about the resolution steps.

Example of Error Messages:

  • Java

java.lang.LinkageError: XYZ has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0

  • Springboot

java.lang.UnsupportedClassVersionError: XYZ has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0

  • Maven

class file has wrong version 61.0, should be 55.0

Java Major Version

These are the Java Major Versions

JavaMajor Version
2064
1963
1862
1761
1660
1559
1458
1357
1256
1155
1054
953
852
751
650
549
1.448
1.347
1.246
1.145
1.0.245

How to check Java Major Version?

Yu can run the below command in your command prompt.

javap -v <path to class file> | grep "major"

Example

$ javap -v build/classes/com/FacingIssuesOnIT/Book.class | grep “major”

How to fix Java Major and Minor Version Issue?

Follow these steps to resolve Java Major & Minor version issue:

Step 1: Go to command prompt and check for Java version

Step 2: In case your system is having more than one version of Java and you want to run your application or code with specific version, then go to Application-> Right click->Select Properties->Go to Build Path->Go to Library and remove the default Library from Class Path and Module Path.

Step 3: Click on Add Library Button and Select JRE System Library, click on Next button. If your JRE on default then select or go to alternate JRE and select Java path as below by Browse button. Click on Apply and Close button and then Finish button

Step 4: Now go to the left panel and select correct compiler version as below and click on apply button.

Step 5: If your application is Maven based then you have to make additional changes in your pom.xml also

Properties Section

<properties>
		<java.version>20</java.version>
</properties>

Plugins Section

   <plugins>    
           <plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<source>20</source>
					<target>20</target>
				</configuration>
			</plugin>
		</plugins>

Now save all your changes and run your application or program. It will work fine.

Reference

https://en.wikipedia.org/wiki/Java_class_file#General_layout

Conclusions

In this post you have learned about the Java Major and Minor version and also to check way of checking through command prompt. If you are facing such exceptions also provided way to resolve it.

Advertisements
Advertisements

Your Feedback Motivate Us

If our FacingIssuesOnIT Experts solutions guide you to resolve your issues and improve your knowledge. Please share your comments, like and subscribe to get notifications for our posts.

Happy Learning !!!

[Solved] Java LinkageError : Compiled by a more recent version of the Java Runtime (class file version X), this version of the Java Runtime only recognizes class file versions up to Y


The java.lang.UnsupportedClassVersionError is a sub-class of LinkageError and ClassFormatError. The JVM (Java Virtual Machine) throw this error when try to read a file but Major and Minor Java version are not supported.

This Java Major and Minor class error occurred while running through IDE eclipse/STS or any because you JAVA_HOME or path or IDE Build Path is configured with different version of Java (JDK/JRE) however your code is compiled with different version of IDE. or Maven pom.xml is configured with different java version while running the program over different JDK/JRE which is not match with Major and Minor version supported.

In further post you will get to know about the resolution steps.

Example of Error Messages:

  • Java

java.lang.LinkageError: XYZ has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0

  • Springboot

java.lang.UnsupportedClassVersionError: XYZ has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0

  • Maven

class file has wrong version 61.0, should be 55.0

Java Major Version

These are the Java Major Versions

JavaMajor Version
2064
1963
1862
1761
1660
1559
1458
1357
1256
1155
1054
953
852
751
650
549
1.448
1.347
1.246
1.145
1.0.245

How to check Java Major Version?

Yu can run the below command in your command prompt.

javap -v <path to class file> | grep "major"

Example

$ javap -v build/classes/com/FacingIssuesOnIT/Book.class | grep “major”

How to fix Java Major and Minor Version Issue?

Follow these steps to resolve Java Major & Minor version issue:

Step 1: Go to command prompt and check for Java version

Step 2: In case your system is having more than one version of Java and you want to run your application or code with specific version, then go to Application-> Right click->Select Properties->Go to Build Path->Go to Library and remove the default Library from Class Path and Module Path.

Step 3: Click on Add Library Button and Select JRE System Library, click on Next button. If your JRE on default then select or go to alternate JRE and select Java path as below by Browse button. Click on Apply and Close button and then Finish button

Step 4: Now go to the left panel and select correct compiler version as below and click on apply button.

Step 5: If your application is Maven based then you have to make additional changes in your pom.xml also

Properties Section

<properties>
		<java.version>20</java.version>
</properties>

Plugins Section

   <plugins>    
           <plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<source>20</source>
					<target>20</target>
				</configuration>
			</plugin>
		</plugins>

Now save all your changes and run your application or program. It will work fine.

Reference

https://en.wikipedia.org/wiki/Java_class_file#General_layout

Conclusions

In this post you have learned about the Java Major and Minor version and also to check way of checking through command prompt. If you are facing such exceptions also provided way to resolve it.

Advertisements
Advertisements

Your Feedback Motivate Us

If our FacingIssuesOnIT Experts solutions guide you to resolve your issues and improve your knowledge. Please share your comments, like and subscribe to get notifications for our posts.

Happy Learning !!!

[Solved] Java UnsupportedClassVersionError : Compiled by a more recent version of the Java Runtime (class file version X), this version of the Java Runtime only recognizes class file versions up to Y


The java.lang.UnsupportedClassVersionError is a sub-class of LinkageError and ClassFormatError. The JVM (Java Virtual Machine) throw this error when try to read a file but Major and Minor Java version are not supported.

This Java Major and Minor class error occurred while running through IDE eclipse/STS or any because you JAVA_HOME or path or IDE Build Path is configured with different version of Java (JDK/JRE) however your code is compiled with different version of IDE. or Maven pom.xml is configured with different java version while running the program over different JDK/JRE which is not match with Major and Minor version supported.

In further post you will get to know about the resolution steps.

Example of Error Messages:

  • Java

java.lang.LinkageError: XYZ has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0

  • Springboot

java.lang.UnsupportedClassVersionError: XYZ has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0

  • Maven

class file has wrong version 61.0, should be 55.0

Java Major Version

These are the Java Major Versions

JavaMajor Version
2064
1963
1862
1761
1660
1559
1458
1357
1256
1155
1054
953
852
751
650
549
1.448
1.347
1.246
1.145
1.0.245

How to check Java Major Version?

Yu can run the below command in your command prompt.

javap -v <path to class file> | grep "major"

Example

$ javap -v build/classes/com/FacingIssuesOnIT/Book.class | grep “major”

How to fix Java Major and Minor Version Issue?

Follow these steps to resolve Java Major & Minor version issue:

Step 1: Go to command prompt and check for Java version

Step 2: In case your system is having more than one version of Java and you want to run your application or code with specific version, then go to Application-> Right click->Select Properties->Go to Build Path->Go to Library and remove the default Library from Class Path and Module Path.

Step 3: Click on Add Library Button and Select JRE System Library, click on Next button. If your JRE on default then select or go to alternate JRE and select Java path as below by Browse button. Click on Apply and Close button and then Finish button

Step 4: Now go to the left panel and select correct compiler version as below and click on apply button.

Step 5: If your application is Maven based then you have to make additional changes in your pom.xml also

Properties Section

<properties>
		<java.version>20</java.version>
</properties>

Plugins Section

   <plugins>    
           <plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<source>20</source>
					<target>20</target>
				</configuration>
			</plugin>
		</plugins>

Now save all your changes and run your application or program. It will work fine.

Reference

https://en.wikipedia.org/wiki/Java_class_file#General_layout

Conclusions

In this post you have learned about the Java Major and Minor version and also to check way of checking through command prompt. If you are facing such exceptions also provided way to resolve it.

Advertisements
Advertisements

Your Feedback Motivate Us

If our FacingIssuesOnIT Experts solutions guide you to resolve your issues and improve your knowledge. Please share your comments, like and subscribe to get notifications for our posts.

Happy Learning !!!

[Solved]: Maven Error “Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project XYZ: There are test failures.”


While running through Run As-> Junit executing Junit test cases but when run through Maven test throwing below error.

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.916 s
[INFO] Finished at: 2021-05-08T04:50:23+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project maven-junit-code-coverage-Jacoco: There are test failures.
[ERROR] 
[ERROR] Please refer to D:\Workspace\maven-junit-code-coverage-Jacoco\target\surefire-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

Problem

In maven java project, maven-surefire-plugin is required for any types of reports generation because mvn test command execute the test cases but there is not added the plug in for maven-surefire-plugin that’s why maven is not able to execute test cases.

Solution

To execute your test cases with Junit in maven Java project, you can add Junit dependency with maven-surefire-plugin.

JUnit 5 Dependency

<dependencies>
	<dependency>
		<groupId>org.junit.jupiter</groupId>
		<artifactId>junit-jupiter-engine</artifactId>
		<version>5.5.2</version>
	</dependency>
</dependencies>

Maven Surefire Report Plugin

<build>
		<plugins> 
			<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.0.0-M5</version>
            <dependencies>
                <dependency>
                    <groupId>org.junit.jupiter</groupId>
                    <artifactId>junit-jupiter-engine</artifactId>
                    <version>5.5.2</version>
                </dependency>
            </dependencies>
        </plugin>
</plugins>
</build>

I have tested this solution with Junit 5 and working perfectly fine for me. You can change this dependency in case using Junit 4.

I have solved this problem by using above solution. If you know any other way to solve it write in comments to help others.

[Solved]: Maven Error “Source option 5 is no longer supported. Use 6 or later”


While build my maven java project getting below exception.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project Sym360: Compilation failure: Compilation failure: 
[ERROR] Source option 5 is no longer supported. Use 6 or later.
[ERROR] Target option 1.5 is no longer supported. Use 1.6 or later.
[ERROR] -> [Help 1]

Problem

This issue is because the maven is not able to identify which version of java compiler need to use while build your code.

Solution

There are two solution to handle such problem.

  1. If you are using simple maven java application then you can add these lines in you pom.xml properties tag .
<properties> 
   <maven.compiler.source>1.8</maven.compiler.source>
   <maven.compiler.target>1.8</maven.compiler.target>
</properties>
  1. If you application is spring boot application and defining maven compiler then add these lines in your pom.xml build tag.
<build>
   <plugins>
   <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.5.1</version>
        <configuration>
            <source>1.8</source>
            <target>1.8</target>
        </configuration>
    </plugin>
   </plugins>
   </build>

Based on your code written and compatibility of java version, you can update this java version like java 11 etc.

I have solved this problem by using these two solution. If you know any other way to solve it write in comments to help others.

Maven Vs Gradle


Gradle is a built tool developed over Maven and Ant. It’s having lots of differences when compared with Maven.

See Also:

MavenGradle
Maven uses XMLGradle doesn’t use XML
Maven written in JavaGradle written in Java, Kotlin and Gradle
Maven scripts are not shorter and cleanGradle Scripts are shorter and clean
Maven is a software project management and builds tool developed for Java-based applications.Gradle is an open-source, build automation system built on concepts of maven and ant.
Maven makes build process easier, provides best guidelines for development and allow to migrate new featuresGradle allows structuring of build and supports for multi projects builds. Gradle increases productivity provides ways to migrate and builds applications.
Advertisements
Advertisements

Your Feedback Motivate Us

If our FacingIssuesOnIT Experts solutions guide you to resolve your issues and improve your knowledge. Please share your comments, like and subscribe to get notifications for our posts.

Happy Learning !!!

Maven Vs Ant


Ant was the first “modern” java application build tool released in 2000. It was famous in a short time because easy to learn, based on procedural programming and not required any additional preparation.

Ant was having some issues in terms of, build time, performance and big scripts and other problems of developers.

Maven releases in 2004 which covers all the problems of Ant and having a complete life cycle.

See Also:

Maven vs Ant

Here are some main differences between Maven and Ant build tool.

AntMaven
Ant required build script per project.Maven describes the project over configuration.
Ant invoke project-specific targetsMaven invoke defined goals (target)
Ant is for “just” build processMaven required knowledge of the project.
Ant scripts are too complex.Maven creates standard project layout and builds in the lifecycle.
Ant scripts are not reusable.Maven plugins and repository are reusable.
Advertisements
Advertisements

Your Feedback Motivate Us

If our FacingIssuesOnIT Experts solutions guide you to resolve your issues and improve your knowledge. Please share your comments, like and subscribe to get notifications for our posts.

Happy Learning !!!

[Solved] Maven Error on Eclipse/STS : Could not calculate build plan org.apache.maven.plugins:maven-jar-plugin:jar:2.4


This maven error generally happen when create maven based web project by using “maven-archtype-console” which generally try to import all library automatically.

You will see this complete error message on pom.xml


Could not calculate build plan: Plugin org.apache.maven.plugins:maven-jar-plugin:2.4 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-jar-plugin:jar:2.4

maven error

POM.XML



  4.0.0
  com.FacingIssuesOnIT
  Spring-Core-Examples
  0.0.1-SNAPSHOT
  Spring-Core-Examples
  Spring Core Exammples

Solution 1:

You need just to follow those steps:
Right Click on your project: Run (As) -> Maven clean
Right Click on your project: Run (As) -> Maven install
After which, if the build fails when you do Maven Install, it means there is no web.xml file under WEB-INF or some problem associated with it.

Solution 2:

Right click on project-> Maven->Click checked box ‘Force Update’->Update

[Solved] Maven Error on Eclipse/STS : Failure to transfer org.apache.maven.plugins:maven-surefire-plugin:pom:2.12.4


This maven error generally happen when create maven based web project by using “maven-archtype-webapp” which generally try to import all library automatically.

You will see this complete error message on pom.xml


Description Resource Path Location Type Failure to transfer org.apache.maven.plugins:maven-surefire-plugin:pom:2.12.4 from http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact org.apache.maven.plugins:maven-surefire-plugin:pom:2.12.4 from/to central (http://repo.maven.apache.org/maven2): The operation was cancelled. pom.xml /SpringCoreTuto line 1 Maven Configuration Problem

POM.XML


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.fiot.example</groupId>
  <artifactId>SpringCoreTuto</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>SpringTuto Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <finalName>SpringCoreTuto</finalName>
  </build>
</project>

Solution 1:

You need just to follow those steps:
Step 1: Right Click on your project: Run (As) -> Maven clean
Step 2: Right Click on your project: Run (As) -> Maven install
After which, if the build fails when you do Maven Install, it means there is no web.xml file under WEB-INF or some problem associated with it.

Solution 2:

Right click on project-> Maven->Click checked box ‘Force Update’->Update

[Solved] Could not transfer artifact org.springframework:XYZ from/to central (https://repo.maven.apache.org/maven2)


Generally this error message shows in pom.xml when create new project with dependencies or add new dependencies in pom.xml.

Reason to cause this error

There are several reason to cause this error as below because maven is unable to connect to Maven repository at http://repo1.maven.org/maven2.

  1. Proxy
  2. Network issue
  3. .lastUpdate file for dependency

Could not transfer artifact org.springframework:spring-expression:jar:5.1.6.RELEASE from/to central (https://repo.maven.apache.org/maven2): C:\Users\saurabh.gupta1\.m2\repository\org
 \springframework\spring-expression\5.1.6.RELEASE\aether-fa07bf3e-4fa1-4911-bcad-3319e4b2480e-spring-expression-5.1.6.RELEASE.jar-in-progress (The system cannot find the file 
 specified) org.eclipse.aether.transfer.ArtifactTransferException:
 

Solutions

There are few ways i find out to resolve this issue:

Maven Force Update of Snapshot/Releases

Follow below steps to to resolve this issue and clear all dependencies error in eclipse.

  1. Right click on project.
  2. Go to Maven
  3. Update project , the check the above option “Force update of Snapshot/Releases“.
  4. Click on Ok.
  5. If not fixed restart your eclipse.

Maven Force Update 1

Maven Force Update 2

Maven access through Proxy

Update your proxy configuration in maven settings.xml file and put it inside .m2 folder

C:\Users\USER NAME.m2

proxy settings





 
    
      myproxy
      true
      http
      user name  
      password   
      127.56.8.64        
      80                 
      local.net|some.host.com 
      
  

You don’t need to touch , and sections, unless you really know what are these tags.

After updating this setting restart eclipse and follow the steps in Maven Force update of Snapshot/Releases.

Remove .lastUpdated file

If this problem is not resolved yet got to .m2/repository/ to dependency sub directory and remove .lastUpdate file inside of it or delete complete directory for this particular dependency and again follow the steps in Maven Force update of Snapshot/Releases.

For Example as for above issue directory location showing in exception as

C:\Users\saurabh.gupta1.m2\repository\org
\springframework\spring-expression\5.1.6.RELEASE

Above solutions are my research to resolve this issue if you find out or know other ways please suggest in comments.

[Solved] Maven: No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK


This maven exception occurs  when your Window/Unix environment variable for JAVA_HOME and PATH are pointing to JRE instead of JDK. That’s why maven will not compile code and throw below exception.

Problem


[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building SpringBootApp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-install-plugin/2.5.2/maven-install-plugin-2.5.2.pom
[INFO] Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-install-plugin/2.5.2/maven-install-plugin-2.5.2.pom (7 KB at 2.3 KB/sec)
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/25/maven-plugins-25.pom
[INFO] Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/25/maven-plugins-25.pom (10 KB at 10.2 KB/sec)
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:resources (default-resources) @ SpringBootApp ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ SpringBootApp ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to D:\Saurabh Gupta\facingIssuesOnIT\SpringBootApp\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.342 s
[INFO] Finished at: 2018-05-28T15:59:31+05:30
[INFO] Final Memory: 20M/209M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project SpringBootApp: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

Solutions

To resolve this issue you can follow below steps by solving command prompt or Eclipse.

Command Prompt

How to Configure Maven in Window and Linux?

Eclipse

  • Right click on project -> Select Properties
  • Select Java Build Path-> Libraries Tab -> Click on Add Library
  • Refer below link for reference.

Eclipse : How to set java path of JDK/JRE?

Advertisements
Advertisements

Your Feedback Motivate Us

If our FacingIssuesOnIT Experts solutions guide you to resolve your issues and improve your knowledge. Please share your comments, like and subscribe to get notifications for our posts.

Happy Learning !!!

Maven Connect Timeout from/to Central “https://repo.maven.apache.org/maven2”


Maven Connect Timeout from/to Central “https://repo.maven.apache.org/maven2&#8221; happen when you are in VPN and proxy network where your office firewall not allowing to download from outside network.

CoreException: Could not calculate build plan: Plugin org.apache.maven.plugins:maven-compiler-plugin:3.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-compiler-plugin:jar:3.1: ArtifactResolutionException: Could not transfer artifact org.apache.maven.plugins:maven-compiler-plugin:pom:3.1 from/to central (https://repo.maven.apache.org/maven2): connect timed out

Solution  1:

  • Try  after exiting  from VPN Network so that your office firewall not stop you to download dependencies.

Solution 2:

  • Update your firewall proxy settings in ./m2/settings.xml or /maven directory/conf/settings.xml file as below
 
    
      optional
      true
      http
      proxyuser
      proxypass
      your.proxy.host
      80
      local.net|some.host.com
    

  

  • Add same file in your eclipse as below Window -> Preference-> Maven -> User Settings
    maven settings.xml path

Click on Apply and then OK.

  • Go to your project -> Right Click ->Maven ->Update Project -> Check Force Update -> Click on OK

Hope that will fix your issue .

Leave you feedback to enhance more on this topic so that make it more helpful for others.

 

How to create Dynamic Web Application using Maven and Eclipse?


In this below example will show steps to create Dynamic Web Project using maven and import to eclipse.

Maven provide maven-archetype-webapp archetype artifact to create Dynamic Web based application from command prompt.

Pre-Requisite

Go to directory/ workspace where you want to create maven Java project. Below is command to create it.

mvn archetype:generate -DgroupId=com.{group}.app -DartifactId={App Name} -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false


Example :

mvn archetype:generate -DgroupId=com.facingissuesonit.app -DartifactId=TestMavenWebApp -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false


Because we are creating our first project with maven that’s why it will download lots of jars and dependency from maven repository.


C:\Users\facingissuesonit\workspace-sample>mvn archetype:generate -DgroupId=com.facingissuesissueonit -DartifactId=TestMavenWebApp
-DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:3.0.1:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO]
[INFO] &lt;&lt;&lt; maven-archetype-plugin:3.0.1:generate (default-cli) &lt; generate-sources @ standalone-pom &lt;&lt;&lt;
[INFO]
[INFO] --- maven-archetype-plugin:3.0.1:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Batch mode
[WARNING] No archetype found in remote catalog. Defaulting to internal catalog
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-webapp:1.0
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: basedir, Value: C:\Users\facingissuesonit\workspace-sample
[INFO] Parameter: package, Value: com.facingissuesissueonit
[INFO] Parameter: groupId, Value: com.facingissuesissueonit
[INFO] Parameter: artifactId, Value: TestMavenWebApp
[INFO] Parameter: packageName, Value: com.facingissuesonit
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: C:\Users\facingissuesonit\workspace-sample\TestMavenWebApp
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 25.374 s
[INFO] Finished at: 2017-06-09T16:52:33-04:00
[INFO] Final Memory: 14M/148M
[INFO] ------------------------------------------------------------------------

Above command will create project with name TestMavenWebApp in your current directory and will show directory structure as below.

TestMavenWebApp
-src
--main
---webapp
----WEB-INF
-----web.xml
----index.jsp
---resources
-pom.xml

Project pom.xml will have entry as below.


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.facingissuesissueonit</groupId>
  <artifactId>TestMavenWebApp1</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>TestMavenWebApp1 Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <finalName>TestMavenWebApp</finalName>
  </build>
</project>

Build Project : Go to project directory and run below command to build your project. It will go through all these steps to complete build life cycle as you can see from console logs.It will create war file for your application.

1. validate
2. generate-sources
3. process-sources
4. generate-resources
5. process-resources
6. compile
7. test

mvn package


C:\Users\facingissuesonit\workspace-sample\TestMavenWebApp>mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building TestMavenWebApp Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ TestMavenWebApp ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ TestMavenWebApp ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ TestMavenWebApp ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\facingissuesonit\workspace-sample\TestMavenWebApp\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ TestMavenWebApp ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ TestMavenWebApp ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-war-plugin:2.2:war (default-war) @ TestMavenWebApp ---
[INFO] Packaging webapp
[INFO] Assembling webapp [TestMavenWebApp] in [C:\Users\facingissuesonit\workspace-sample\TestMavenWebApp\target\TestMavenWebApp]
[INFO] Processing war project
[INFO] Copying webapp resources [C:\Users\facingissuesonit\workspace-sample\TestMavenWebApp\src\main\webapp]
[INFO] Webapp assembled in [65 msecs]
[INFO] Building war: C:\Users\facingissuesonit\workspace-sample\TestMavenWebApp\target\TestMavenWebApp.war
[INFO] WEB-INF\web.xml already added, skipping
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.352 s
[INFO] Finished at: 2017-06-10T14:37:25-04:00
[INFO] Final Memory: 12M/114M
[INFO] -------------------------------------------------------------------

Now our build is successful and architecture created by maven is ready. Now time to import this project in eclipse.

Import to Eclipse : To import this project in eclipse first we need to convert this project according to eclipse and then import it.

  • Convert to Eclipse Maven Project : Use below command
    mvn eclipse:eclipse -Dwtpversion=2.0

C:\Users\facingissuesonit\workspace-sample\TestMavenWebApp>mvn eclipse:eclipse -Dwtpversion=2.0
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building TestMavenWebApp Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-eclipse-plugin:2.10:eclipse (default-cli) > generate-resources @ TestMavenWebApp >>>
[INFO]
[INFO] <<< maven-eclipse-plugin:2.10:eclipse (default-cli) < generate-resources @ TestMavenWebApp <<<
[INFO]
[INFO] --- maven-eclipse-plugin:2.10:eclipse (default-cli) @ TestMavenWebApp ---
[INFO] Adding support for WTP version 2.0.
[INFO] Using Eclipse Workspace: C:\Users\facingissuesonit\workspace-sample
[WARNING] Workspace defines a VM that does not contain a valid jre/lib/rt.jar: C:\Program Files\Java\jre1.8.0_73
[INFO] Adding default classpath container: org.eclipse.jdt.launching.JRE_CONTAINER
[INFO] Not writing settings - defaults suffice
[INFO] Wrote Eclipse project for "TestMavenWebApp" to C:\Users\facingissuesonit\workspace-sample\TestMavenWebApp.
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.608 s
[INFO] Finished at: 2017-06-09T16:54:24-04:00
[INFO] Final Memory: 14M/115M
[INFO] ------------------------------------------------------------------------ 

Import in Eclipse : Follow below steps to import TestMavenWebApp project in Eclipse

Eclipse File -> Import -> General-> Existing Project in Workspace -> Select Project TestMavenWebApp

It will show some compile time issue on index.jsp page because   not attached with any Web Server and also select Java compiler version from facet as given screen.

TestMavenWebApp Project -> Right Click ->Properties -> Project Facets

Select Runtime and Java compiler version as configured in class path. Click on apply and OK.

maven web facet server

Your Project is ready to more development and configured in eclipse . It will have below directory Structure.

Maven Web Project Directory

Run Project:

TestMavenWebApp Project ->Run As ->Run On Server

We will get below screen after successful execution.

Maven Web Run

Leave you feedback to enhance more on this topic so that make it more helpful for others.

 

Advertisements
Advertisements

Your Feedback Motivate Us

If our FacingIssuesOnIT Experts solutions guide you to resolve your issues and improve your knowledge. Please share your comments, like and subscribe to get notifications for our posts.

Happy Learning !!!

How to add 3rd Party/Custom/External Jars to Maven Project?


In below steps will show about to add 3rd party/custom/external Jars in local repository for use in our project builds because these jars doesn’t exist in Maven public repository and required to build project.

Pre-Requisite

To add these jars we can use below command to load in local repository (.m2/repository)

mvn install:install-file -Dfile= -DgroupId=
-DartifactId= -Dversion= -Dpackaging=

Example : Oracle is 3rd party and it’s jars are available in maven public repository. We can use below command to store in maven local repository and make entry in pom.xml to use it.

mvn install:install-file -Dfile=C:\\Workspace\\ojdbc6.jar -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar

pom.xml entry for above oracle jar

 <dependency>
	<groupId>com.oracle</groupId>
	<artifactId>ojdbc6</artifactId>
	<version>11.2.0</version>
</dependency>

 

Advertisements
Advertisements

Your Feedback Motivate Us

If our FacingIssuesOnIT Experts solutions guide you to resolve your issues and improve your knowledge. Please share your comments, like and subscribe to get notifications for our posts.

Happy Learning !!!

How to create Maven Java Console Project?


In this below example will show you create maven java project from console and import to eclipse.

Maven provide maven-archetype-quickstart archetype artifact to create console based java project from command prompt.

Pre-Requisite

Go to directory/ workspace where you want to create maven Java project. Below is command to create it.

mvn archetype:generate -DgroupId=com.{group}.app -DartifactId={App Name} -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false


Example :

mvn archetype:generate -DgroupId=com.facingissuesonit.app -DartifactId=test-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false


Because we are creating our first project with maven that’s why it will download lots of jars and dependency from maven repository.


C:\Users\facingissuesonit\workspace-sample>mvn archetype:generate -DgroupId=com.facingissuesonit.app -DartifactId=test-app -DarchetypeArtifactId=maven-archetype
-quickstart -DinteractiveMode=false

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:3.0.1:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO]
[INFO] &lt;&lt;&lt; maven-archetype-plugin:3.0.1:generate (default-cli) &lt; generate-sources @ standalone-pom &lt;&lt;&lt;
[INFO]
[INFO] --- maven-archetype-plugin:3.0.1:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Batch mode
[WARNING] No archetype found in remote catalog. Defaulting to internal catalog
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-quickstart:1.0
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: basedir, Value: C:\Users\facingissuesonit\workspace-sample
[INFO] Parameter: package, Value: com.facingissuesonit.app
[INFO] Parameter: groupId, Value: com.facingissuesonit.app
[INFO] Parameter: artifactId, Value: test-app
[INFO] Parameter: packageName, Value: com.facingissuesonit.app
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: C:\Users\facingissuesonit\workspace-sample\test-app
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 24.133 s
[INFO] Finished at: 2017-06-06T03:55:59-04:00
[INFO] Final Memory: 14M/148M
[INFO] ------------------------------------------------------------------------

Above example command will create project with name test-app in your current directory and will show directory structure as below.

Test-app
-src
--main
---java
----com
-----facingissuesonit
------app
-------App.java
--test
---java
----com
-----facingissuesonit
------app
-------AppTest.java
-pom.xml

Project pom.xml will have entry as below.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.facingissuesonit.app</groupId>
  <artifactId>test-app</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>test-app</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

Build Project : Go to project directory and run below command to build your project. It will go through all these steps to complete build life cycle as you can see from console logs.

1. validate
2. generate-sources
3. process-sources
4. generate-resources
5. process-resources
6. compile
7. test

mvn package


C:\Users\facingissuesonit\workspace-sample\test-app>mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building test-app 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ test-app ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\facingissuesonit\workspace-sample\test-app\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ test-app ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to C:\Users\facingissuesonit\workspace-sample\test-app\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ test-app ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\facingissuesonit\workspace-sample\test-app\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ test-app ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to C:\Users\facingissuesonit\workspace-sample\test-app\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ test-app ---
[INFO] Surefire report directory: C:\Users\facingissuesonit\workspace-sample\test-app\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.facingissuesonit.app.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.007 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ test-app ---
[INFO] Building jar: C:\Users\facingissuesonit\workspace-sample\test-app\target\test-app-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.372 s
[INFO] Finished at: 2017-06-06T04:07:45-04:00
[INFO] Final Memory: 16M/145M
[INFO] -------------------------------------------------------------------

Now our build is successful. We can use below command in target folder to run test-app project.

C:\Users\facingissuesonit\workspace-sample\test-app\target>java -cp test-app-1.0-SNAPSHOT.jar com.facingissuesonit.app.App
Hello World!

Import to Eclipse : To import this project in eclipse first we need to convert this project according to eclipse and then import it.

  • Convert to Eclipse Maven Project : Use below command
    mvn eclipse:eclipse

C:\Users\facingissuesonit\workspace-sample\test-app&gt;mvn eclipse:eclipse
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building test-app 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] &gt;&gt;&gt; maven-eclipse-plugin:2.10:eclipse (default-cli) &gt; generate-resources @ test-app &gt;&gt;&gt;
[INFO]
[INFO] <<< maven-eclipse-plugin:2.10:eclipse (default-cli) < generate-resources @ test-app <<< [INFO] 
[INFO] --- maven-eclipse-plugin:2.10:eclipse (default-cli) @ test-app --- 
[INFO] Using Eclipse Workspace: C:\Users\facingissuesonit\workspace-sample 
[WARNING] Workspace defines a VM that does not contain a valid jre/lib/rt.jar: C:\Program Files\Java\jre1.8.0_73 
[INFO] Adding default classpath container: org.eclipse.jdt.launching.JRE_CONTAINER [INFO] Not writing settings - defaults suffice 
[INFO] Wrote Eclipse project for &quot;test-app&quot; to C:\Users\facingissuesonit\workspace-sample\test-app. 
[INFO] 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 2.717 s [INFO] Finished at: 2017-06-06T04:56:14-04:00 [INFO] Final Memory: 12M/114M 
[INFO] -------------------------------------------------------------------

Import in Eclipse : Follow below steps to import test-app project in Eclipse

Eclipse File -> Import -> General-> Existing Project in Workspace -> Select Project test-app

Maven Java Console Project
Advertisements
Advertisements

Your Feedback Motivate Us

If our FacingIssuesOnIT Experts solutions guide you to resolve your issues and improve your knowledge. Please share your comments, like and subscribe to get notifications for our posts.

Happy Learning !!!

How to Configure Maven in Window and Linux?


Configuration in Maven  in Window and Linux required below steps.

  • Download latest version of maven from below link

Download Link : http://maven.apache.org/

Configuration in Window

  • Unzip file apache-maven-X.X.X-bin.zip and change unzip file name like name as maven. It will have directory structure like below
  • window maven directory
    Maven Directory Structure
  • Copy this maven folder to C:\Program Files (x86) directory.
  • Add below Environment Variable by right click on My Computer -> Properties-> Environment Variable/Advance System Settings
    User Environment Variable
    
    M2_HOME : C:\Program Files (x86)\maven
    M2: %M2_HOME%\bin
    PATH : %M2%;
    
    If you already have any value in PATH add %M2%;   after end of value.
    

    It will show as below in screen shot

    maven environment variable window

  • Close all console instances/Command prompt if running and open new command prompt and run below command and will receive output with version of Maven and Java.
    mvn –-version 
    
    C:\Users\FacingIssuesOnIT>mvn --version
    Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T11:41:47-05:00)
    Maven home: C:\Program Files (x86)\maven
    Java version: 1.8.0_73, vendor: Oracle Corporation
    Java home: C:\Program Files\Java\jdk1.8.0_73\jre
    Default locale: en_US, platform encoding: Cp1252
    OS name: "windows 7", version: "6.1", arch: "amd64", family: "dos"
    

Configure in Linux

Download latest version of Maven and Untar it with below command

tar -zxvf  apache-maven-3.5.0-bin.tar.gz

change name of directory as apache-maven-3.5.0 and set maven environment variable as below for configuration

$ export M2_HOME=/opt/app/facingissuesonit/apache-maven-3.5.0

$ export M2=$M2_HOME/bin
Set below for memory configuration
$ export MAVEN_OPTS=-Xms256m -Xmx512m
with M2_Home path corresponding with the location of your extracted Maven files.

Now append the M2 environment variable to the system path as below:

$ export PATH=$M2:$PATH

To check maven install successfully follow below command

mvn --version

Apache Maven 3.5.0 (r801777; 2009-08-06 15:16:01-0400)
Java version: 1.8.0_73
Java home: /opt/app/facingissuesonit/posbea/jdk-1.8.0_73/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux" version: "2.6.32-642.6.2.el6.x86_64" arch: "i386" Family: "unix"