⬆️ ⬇️

Maven: Answers to Questions



I was asked a question, the answer to which I want to share not only with the questioner, but also with the rest of the audience. Just in case, that, yes, and it turns out to be useful. In addition, I am ready to answer other questions habrovchan who directly or indirectly relate to the Maven.

I intend to make this article not quite ordinary and update as new questions with answers appear.



The question sounded like this: How to create a spring mvc project, and connect the required libraries, for example hibernate, install it on tomcat, and then work with this project in eclipse?

What would not answer messy and all at once, let's divide the question.
  1. Creating a Maven Project
  2. Connecting Libraries (Dependencies) to Maven
  3. Deploy (install) the project to the application server.
  4. Maven interaction with the development environment.


A little introduction.



Almost all Maven does with the help of plug-ins, which itself downloads and updates from repositories known to it. Thus, if in the future you want to make Maven do something with the project, you need to find (or write) a plugin that will do it. Some plugins can be launched only during the execution phase of the project, and some plugins do not require a project at all.



1. Creating a project.


Maven creates projects using the Maven Archetype Plugin. You can create a project or completely zero, using the command:
mvn archetype:create -DgroupId=com.oracle.java -DartifactId=MyProject 
groupId is the group ID of the project (usually the company name + product) for example com.oracle.javafx

artifactId - immediate identifier of the project in the group

(In general, all projects in Maven are uniquely identified by the three components Group, ID, version.)

')

Or, you can create a project by specifying an archetype (template / blank) for which it should be created:
 mvn archetype:generate -DarchetypeGroupId=org.appfuse.archetypes -DarchetypeArtifactId=appfuse-basic-spring -DarchetypeVersion=2.0 -DgroupId=com.mysite.sample -DartifactId=mySpringMVCProject -DinteractiveMode=false 
In this command, the plug-in is given a set of parameters that determine how and by what architect to create a project. Each parameter begins with a "-D" and ends with a space. (-D <ParameterName> = <ParameterValue>)



If from thousands of architects you still haven’t found one close to you in spirit, then you can create your own.



2. Connection of libraries (dependences) in Maven


To connect the library to the project on Maven, it is necessary that the library also be a project on Maven and lay in the repository about which your Maven "knows". If you only have a jar file that you want to use as a library, then this question can be solved.



3. Deploy (install) a project to an application server.


The tomcat-maven-plugin (your CEP) deals with tomcat. In order for the project to be updated on the tomcat phase, you need to find the project.build.plugins branch in the project xml and add the following code xml to it.
 <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>tomcat-maven-plugin</artifactId> <configuration> <!--       tomcat --> <!-- :--> <warDirectory>path/to/my/warDir</warDirectory> </configuration> </plugin> 
You can read about the possible settings of the plugin and see examples here .



4. Maven interaction with the development environment.
Maven is already quite well known and many development environments are able to simply open its projects (for example, NetBeans). But eclipse still needs a project in its own format. You can also get Eclipse using the plugin:
 mvn eclipse:eclipse 
PS

The topic does not pretend to complete the presentation of the material, is a kind of experiment and is specifically placed in the Personal Blogs, so if you still have a keen desire to put a minus (no matter where), please take a couple of minutes to substantiate.

Thank.

Source: https://habr.com/ru/post/137059/



All Articles