Tools used
Eclipse (Helios)
Maven Integration for Eclipse (Help->Eclipse Marketplace and install it.)
Exec Maven Plugin
Create new Maven project.
Now generated project structure look like this.
Generated pom.xml
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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>codesstore</groupId> <artifactId>codesstore-core</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>codesstore-core</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project>
I created a new class called MyClass.java in com.codesstore.util package.
MyClass.java
And called that class in main method.package com.codesstore.util; public class MyClass { public void printHello() { System.out.println("Hello Maven..."); } }
App.java
Now I'm going to add Exec plugin to pom.xml. See more information on Exec plugin http://mojo.codehaus.org/exec-maven-plugin/package com.codesstore.main; import com.codesstore.util.MyClass; public class App { public static void main(String[] args) { new MyClass().printHello(); } }
pom.xml
Right click on the pom file -> Run as ->Maven build..<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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>codesstore</groupId> <artifactId>codesstore-core</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>codesstore-core</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.1-beta-1</version> <executions> <execution> <goals> <goal>java</goal> </goals> </execution> </executions> <configuration> <mainClass>com.codesstore.main.App</mainClass> </configuration> </plugin> </plugins> </build> </project>
Then you can set goals to run. I use exec:java here.
Out put
Project structure in Eclipse
Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
ReplyDeletePython Training in electronic city
DataScience with Python Training in electronic city
AWS Training in electronic city
Big Data Hadoop Training in electronic city
Devops Training in electronic city
blockchain Training in electronic city
Hibernate Training in electronic city