(7) Best practices for Maven and best practices for maven
It is not necessary to use Maven, but some useful practices may solve your problem at critical moments.
1. Set MAVEN_OPTS Environment Variables
Generally, MAVEN_OPTS must be set to-Xms128m-Xmx512m, because the default maximum available memory of Java cannot meet the needs of running Maven. For example, when a project is large, using Maven to generate a project site requires a large amount of memory. Without this configuration, it is easy to get java. lang. outOfMemeoryError is abnormal. Therefore, it is recommended to configure the environment variable from the beginning.
For more information about how to set environment variables, see the previous section.
2. Configure the user scope settings. xml
Maven users can choose to configure settings. xml under the Maven installation directory conf or the settings. xml under the System user directory. m2. The former is global, and all users on the entire machine are directly affected by this configuration. The latter is user-specific, and only the current user is affected by this configuration.
We recommend that you use settings. xml in the user scope to avoid unintentional impact on other users in the system. If you have actual requirements, you need to unify the settings. xml configurations of all users in the system. Of course, you should use global settings. xml.
In addition to the impact scope, configuring the user scope settings. xml file also facilitates Maven upgrade. Directly modifying settings. xml in the conf directory will cause the Maven upgrade inconvenience. Copy the settings. xml file every time you upgrade to the new version of Maven. If you use settings. xml in the. m2 directory, the Maven installation file will not be affected. During the upgrade, you do not need to touch the settings. xml file.
Generally, the settings. xml configuration file does not exist in the. m2 directory. You need to copy the settings. xml file under the conf file to the. m2 directory and then modify it.
3. Do not use Maven embedded in IDE
Eclipse installs an embedded Maven when integrating Maven. This embedded Maven is usually newer, but not necessarily stable, in addition, it is often different from the Maven version used in the command line. There are two potential problems: first, there are many unstable factors in the newer versions of Maven, which may cause some difficult-to-understand problems. Second, apart from IDE, maven of the command line is also often used. If the versions are inconsistent, the build behavior may be inconsistent, which we do not want to see. Therefore, Maven that is consistent with the command line should be used when configuring Maven plug-ins in IDE.
In the Eclipse environment, click Window in the menu bar and select Preferences. In the displayed dialog box, expand Maven items on the left and select the Installations sub-item. In the right pane, we can see that a default EMBEDDED Maven installation is selected. Click Add..., select the Maven installation directory, select Maven we installed, and click OK,
Other similar ides may be embedded with Maven during integration. Similarly, we 'd better change it to the Maven we installed on our own.
4. Specify the settings. xml configuration file used in Eclipse.
In the Eclipse environment, click Window in the menu bar, select Preferences, expand Maven items on the left in the pop-up dialog box, select User Settings sub-item, and in the right panel, click Browse... and then select the corresponding settings. after setting the xml file, click OK,
Alan uses settings in the conf directory. xml to unify the settings of all users in the system. xml configuration. Other Similar ides should also have settings for specific settings. xml.