Showing posts with label eclipse. Show all posts
Showing posts with label eclipse. Show all posts

Thursday, October 10, 2024

Creating a Maven Project in Eclipse

This tutorial shows how to create a Maven project in Eclipse. Here I am using the maven Eclipse plugin. These days Eclipse comes pre-configured with maven plugin and you don't need to download and set up maven plugin yourself. To verify that you have maven plugin pre-configured in eclipse go to Windows - Preferences, there on the left side scrollable window search for Maven, if you have maven then it will look like this.

maven project in eclipse

Creating Maven project structure in Eclipse

In Eclipse select File - New - Maven Project

That will open a Wizard for creating “New Maven Project”, check “Create a simple project (skip archetype selection)”. Click Next.

Maven project eclipse

In the next window provide group ID and artifact ID and other details.

  • groupId- This element indicates the unique identifier of the organization or group that created the project. GroupId is typically based on the fully qualified domain name of your organization. For example com.companyName.finance is the designated groupId for all finanace related projects.
  • artifactId- This element indicates the unique base name of the primary artifact being generated by this project. The primary artifact for a project is typically a JAR file. A typical artifact produced by Maven would have the form -. (for example, myapp-1.0.jar).
  • packaging- This element indicates the package type to be used by this artifact (e.g. JAR, WAR, EAR, etc.). The default value for the packaging element is JAR so you do not have to specify this for most projects.
  • version- This element indicates the version of the artifact generated by the project.
  • name- This element indicates the display name used for the project. This is often used in Maven's generated documentation.
  • description- This element provides a basic description of your project. This is often used in Maven's generated documentation.
Maven project in Eclipse

Click Finish. You should get a project structure similar to as shown below.

You can change the default JRE system library to current Java version by going to Java build path and changing the JRE library.

That's all for this topic Creating a Maven Project in Eclipse. If you have any doubt or any suggestions to make please drop a comment. Thanks!

>>>Return to Java Advanced Tutorial Page


Related Topics

  1. Spring Example Program Using XML Configuration
  2. Spring Example Program Using JavaConfig And Annotations
  3. Spring Example Program Using Automatic Configuration
  4. Autowiring Using Annotations in Spring
  5. How to Pass Command Line Arguments in Eclipse

You may also like-

  1. Encapsulation in Java
  2. Interface Default Methods in Java
  3. Difference Between Abstract Class And Interface in Java
  4. How to Sort an ArrayList in Descending Order in Java
  5. Java CountDownLatch With Examples
  6. Check Given Strings Anagram or Not Java Program
  7. Add Double Quotes to a String Java Program
  8. Spring NamedParameterJdbcTemplate Insert, Update And Delete Example

Tuesday, March 8, 2022

How to Pass Command Line Arguments in Eclipse

Eclipse is one of the most preferred IDE for Java/JEE development. Eclipse IDE provides various options like running the application from the IDE, providing arguments to your Java program, debugging your application. In this post we’ll see how to pass command line arguments to your Java program through Eclipse IDE.

Let’s take an example Java program where you have to add the two passed arguments and print the total.

public class Add {
 public static void main(String[] args) {
  try{
   if(args.length != 2){
    throw new IllegalArgumentException("Argument length "
      + "should be 2 ");
   }
  }catch(IllegalArgumentException IAexp){
   System.out.println("Error in the code - " + IAexp.getMessage()); 
  }
  double total = Double.parseDouble(args[0]) + Double.parseDouble(args[1]);
  System.out.println("Sum of " + args[0] + " and " + args[1] + " is: " + total);
 }
}

How to pass arguments in eclipse

You can select “Run Configuration” option by selecting the Run menu from the top menu.

Selecting Run Configuration option from Run menu

You can also select the same “Run Configuration” option by right clicking the program for which you have to provide args, from the package explorer.

command line arguments in eclipse
Selecting Run Configuration option from package explorer

That will open the “Run Configuration” screen.

Run Configuration screen

Make sure that the program where arguments are to be passed is selected.If you don’t find your program there search for it or add it by right clicking on “Java Application” and selecting New.

In the “Run Configuration” screen select the “Arguments” tab and provide required arguments in the “Program arguments” text area. Then select Apply and then Run to run you program.

command line arguments in eclipse

That's all for this topic How to Pass Command Line Arguments in Eclipse. If you have any doubt or any suggestions to make please drop a comment. Thanks!

>>>Return to Java Advanced Tutorial Page


Related Topics

  1. Creating a Maven Project in Eclipse
  2. Why Class Name And File Name Should be Same in Java
  3. Why main Method static in Java
  4. Java Pass by Value or Pass by Reference
  5. Java Abstract Class and Abstract Method

You may also like-

  1. Why no Multiple Inheritance in Java
  2. static Block in Java
  3. Lambda Expression Examples in Java
  4. Effectively Final in Java 8
  5. How ArrayList Works Internally in Java
  6. Difference Between HashMap And ConcurrentHashMap in Java
  7. Volatile Keyword in Java With Examples
  8. AutoBoxing And UnBoxing in Java

Saturday, February 1, 2020

Adding Tomcat Server to Eclipse

This post shows how you can add Apache Tomcat server to the Eclipse IDE and start and stop it from Eclipse IDE itself.

Downloading Apache Tomcat Server

If you don’t have Tomcat server yet you can download it from here- https://tomcat.apache.org/download-90.cgi

Latest version at the time of writing this post is 9.0.10.

Once downloaded, extract it to a folder.

Adding Tomcat server to Eclipse

In Eclipse IDE, go to Servers tab and in the Server area- Right click – New – Server

Adding new server eclipse

In the opened “Define a New Server” window expand Apache and select the Tomcat version you want to configure. For example if you have downloaded Tomcat 9.x version then select Tomcat v9.0 Server. Click Next.

defining new server

In the next window browse to the directory where you have extracted your downloaded Tomcat server. Ensure that the correct Java version is also selected.

adding tomcat server

If you already specified some resources to run with Tomcat, in the next window you get a chance to add those resources to the configured Tomcat server. For example I already have one Spring Web MVC application configured to run on Tomcat server so I can add it to the configured server in this window. Click Finish.

add resources to Tomcat server

You should see a new Tomcat server added in the Server area. On double clicking it you can see the configuration for the server and right clicking it will give you option to start, stop, clean etc.

tomcat server in eclipse

That's all for this topic Adding Tomcat Server to Eclipse. If you have any doubt or any suggestions to make please drop a comment. Thanks!

>>>Return to Java Advanced Tutorial Page


Related Topics

  1. How to Pass Command Line Arguments in Eclipse
  2. Creating a Maven Project in Eclipse
  3. Reflection in Java
  4. Spring Example Program Using Automatic Configuration
  5. Spring Web MVC Example With Annotations And XML Configuration

You may also like-

  1. Serialization in Java
  2. Object Cloning in Java
  3. Nested Class And Inner Class in Java
  4. Garbage Collection in Java
  5. String Vs StringBuffer Vs StringBuilder in Java
  6. Array in Java
  7. Lazy Initializing Spring Beans
  8. Introduction to Hadoop Framework