10 May Java Advanced Maven Hello World Project
I need a Hello World Project for Maven
- Install Maven on Windows (See the box below for Mac directions):
- Download the zip archive of latest version of Maven. Be sure to download the binary zip, not the source (“src”) zip!
- Extract it to someplace. I suggest
C:\Java\
(used in the directions that follow), but anyplace you wish is fine. - I suggest you rename the folder from
apache-maven-
version
to something simpler, such as justmaven
. - Add this entry to the
PATH
environment variable:C:\Java\maven\bin
(use the folder name you picked). - Add this new environment variable:
M2_HOME=C:\Java\maven
- Make sure you have the following environment variable set:
JAVA_HOME=C:\java
(or whatever location you used for the JDK). - (As a reminder:
PATH
is used by your system to locate executables such asmvn
orjava
;CLASSPATH
is used by Java to locate packages and some other things;JAVA_HOME
is used by various programs (including Maven) to locate a JDK; andM2_HOME
(previously known asMAVEN_HOME
) is used bymvn
to locate various configuration files. All of these may be used by other programs to locate files they need. While some programs are smart enough to guess to try default install locations when you don’t set these variables, that won’t work if you don’t install in the default locations.)
Install Maven on Mac OS X
There are several ways do to this. One is to follow the standard install directions for a Linux-like system, found on the Maven website. The simplest way seems to be this: - Install Homebrew if you don’t already have that: visit brew.sh, copy the long line shown, and paste it in a terminal window. Doing this provides you with the
brew
command to install things. - Run the command
brew install maven
. - If your version of OS X doesn’t include the
tree
command, you can install that using the commandbrew install tree
.
- First, pick (or create) an empty directory to hold your Maven projects, and
cd
into it. Next, create a working “Hello, World” project named “hello
” using the command (one long line):mvn archetype:generate -DgroupId=cop2805 -DartifactId=hello -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
That might take a while the first time. When done, see what files were created by using thetree/F hello
command (justtree
on Mac or Linux). Also take a look in your home directory; you should see a new subdirectory there named.m2
. That’s your personal Maven repo. - Next
cd
into your newhello
directory. Take a look at the generated source code atsrc/main/java/cop2805/App.java
, the generated unit test atsrc/main/java/cop2805/App.java
, and the generatedpom.xml
file. (When using Maven “for real”, you would edit the POM file and then edit or replace theApp.java
andAppTest.java
files.) - If using Java 9, you will need to add some lines to your
pom.xml
file. The reason is, the current version of Maven’s compile plugin tries to generate code compatible with Java 5 (“javac -release 5 -source 5
”), and Java 9 only supports Java 6 through 9. To fix, you need to add these four lines in your generatedpom.xml
: <properties> <maven.compiler.source>1.9</maven.compiler.source> <maven.compiler.target>1.9</maven.compiler.target> </properties>
Those lines can go anywhere between the initial <project> tag and the final </project> tag, but not inside of any other tags. Just above the final </project> tag is fine. (Hopefully, a new version of that plugin will address that problem!) - Next, compile, test, package, and install your project. Maven will automatically put a copy into your local repo,
~/.m2/
(“~
” means your home directory.). This is done with the simple command:mvn install
Run thetree/F
(ortree
) command to see the new files created. (Also look in your home directory and usetree
on the.m2
directory there.) Notice the JAR file; that is the resulting application. To run this Jar file, enter the command (without changing directories first):
java -cp target\hello-1.0-SNAPSHOT.jar cop2805.App - Finally, there are a couple of other Maven commands to play with:
- Try “
mvn site
” to generate a website for your project. You can view the site in your web browser by opening the file “.../hello/target/site/
”. - Convert your Maven project to an Eclipse-Maven project: “
mvn eclipse:eclipse
”. If you import this project into Eclipse, it should just work. - Try to convert your “Hello, world” projects from the two IDEs into Maven projects. Notice how the layout of folders is now different from the default for your Eclipse and NetBeans IDEs.
- Try “
Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteDemy. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.
About Writedemy
We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.
How It Works
To make an Order you only need to click on “Order Now” and we will direct you to our Order Page. Fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Are there Discounts?
All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.