Tag Archives: eclipse

How to Enable YAML Editor in Eclipse?


Below are steps to Enable YAML/YML editor on eclipse IDE.

  • Open Eclipse IDE
  • Go to Help menu -> Eclipse Marketplace.
  • Search for term “YAML”
  • You will get lots of option select “YAML Editor” and click on install as in below screen.
YAML Editor in Eclipse
Enable YAML/YML Editor on Eclipse
  • Click check box corresponding to “Accept Terms and Conditions”.
  • Click on Apply button and restart eclipse.

More

To know more about YAML Syntax, Configuration with Java and other supporting language, frameworks and tools, Sample configuration files and JSON and YAML conversion follow below YAML Tutorials and YAML related exceptions follow YAML Issues.

 

How to make and auto run /executable jar with dependencies?


To make auto run/executable jar by eclipse follow below steps.

  • Create Java Project in Eclipse by following these steps as below New -> Project ->Java Project -> Click Next
  • Type Project Name as JavaAutoRunExample -> click on Finish button.
  • Expend project JavaAutoRunExample on left panel and create package as com.facingissuesonit.test
  • Create below class TestHelloWorld inside package com.facingissuesonit.test
    package com.facingissuesonit.test;
    
    public class TestHelloWorld {
    
    	public static void main(String[] args) {
    		System.out.println("Inside Package facing Issues on IT");
    		System.out.println("Test Hello World !!");
    	}
    
    }
    

Now your Project Structure will looks like as below.

Auto Run Jar Project

Now in below steps will show  to convert this project as auto run/executable jar where entry point would be main method of class TestHelloWorld.

Note : If in your project having multiple classes having main method you can decide one entry point by below steps.

  • Build and Test you project so that there would be any compile and runtime issues. Select class TestHelloWord -> Right click -> Run As -> Java Application. You will get below console output.
    Inside Package facing Issues on IT
    Test Hello World !!
    
  • Right Click on JavaAutoRunExample ->export ->Java->Runnable Jar File -> Click on Next.

Auto run Jar Selection

  • Select Launch Configuration as TestHelloWorld and export destination where want to keep this auto run/executable jar and dependency jar options as below.Auto Run lanunch Selection
  • Now your auto run/executable jar is ready . For executing it go to command promt (CMD) and select location for file and use below command

java -jar AutoRunTest.jar

C:\Users>cd C:\Users\facingissuesonit\Documents

C:\Users\facingissuesonit\Documents>java -jar AutoRunTest.jar
Inside Package facing Issues on IT
Test Hello World !!

 

 

Hope this blog was helpful for you.

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

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] <<< maven-archetype-plugin:3.0.1:generate (default-cli) < generate-sources @ standalone-pom <<<
[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>mvn eclipse:eclipse
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building test-app 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-eclipse-plugin:2.10:eclipse (default-cli) > generate-resources @ test-app >>>
[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 "test-app" 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