Summary of frequently asked questions about using Maven (issues such as using MAVEN, MAVEN project deployment to Tomcat in Eclipse)

Source: Internet
Author: User
Tags sonatype

Some recent projects need to be managed by MAVEN, one of which is to add the previous Eclipse Java Project Project and Web project to MAVEN management, and another scenario is to pull the MAVEN project on SVN locally, Some of the tricky issues encountered in using eclipse, the problem process, and the solution are as follows:

1. When you start eclipse after installing the Maven plugin in Eclipse, you encounter the following warning :

The MAVEN integration requires that Eclipse is running in a JDK, because a number of Maven core plugins is using jars fro M The JDK

Sure THE-VM option in Eclipse.ini was pointing to a JDK and verify that installed JRE's is also using JDK ins talls.

2. The following issues may occur when compiling in eclipse with the Maven plugin or maven install:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:testcompile (Default-testcompile) on Project Springside-core:compilation Failure

[ERROR] No compiler is provided in this environment. Perhaps is running on a JRE rather than a JDK?

The above two problem solving methods are as follows:

(1)set your JDK as a default Java environment in eclipse (default installed JRE)

Open Eclipse. Click on ' Window ', ' Preferences ', ' Java ', ' Installed JREs '.

If you can ' t find any JDK on the list, click ' Add ', ' Standard VM ', set all paths and click ' Finish '.

After That–check this JDK is on the list of installed JREs and click ' OK '.

Sometimes the adoption of option (1) would not be an effective solution to the problem and would require the following treatment:

(2)add path to your SDK in Eclipse.ini

Open ' Eclipse.ini ' and add there:-VM Path_to_javaw_on_your_machine,so in my example it'll be (jdk1.6.0_17 on Windows):

-vm
D:\\java\jdk1.6.0_13\jre\bin\javaw

Your ' Eclipse.ini ' looks like this:

-startup
Plugins/org.eclipse.equinox.launcher_1.0.201.r35x_v20090715.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.0.200.v20090519
-showsplash
Org.eclipse.platform
--launcher. Xxmaxpermsize
256m

-vm
D:\Java\jdk1.6.0_13\jre\bin\javaw
-vmargs
-xms40m

-xmx256m

Note:'-VM ' must be "-vmargs" above

3. Using Maven, you will often build your own nexus with the following steps:

Advantages of establishing A:

(1) Reduce the central warehouse load

(2) Saving external network bandwidth

(3) Accelerating MAVEN Build

(4) Deploy components yourself

1). Nexus Installation

(1) Download: http://www.sonatype.org/nexus/, download package: Nexus-2.0.2.war

(2) Installation

A. War Mode installation Nexus

Copy the Nexus-2.0.2.war to the deployment directory of Tomcat: C:\Apache-tomcat-7.0.26\webapps,

Start Tomcat and enter the Tomcat Admin homepage.

Browser Access address : Http://localhost:8080/nexus

B. Bundle way to install Nexus

Because the bundle mode Nexus is integrated with the jetty container by default, no other third-party web container is required to extract the downloaded bundle

The Nexus file of the way, has the following two directories:

nexus-webapp-2.0.2: Contains the files required by the Nexus, such as startup scripts, dependent jars, and so on.

Sonatype-work: Contains configuration files, log files, and warehouse files generated by the Nexus.

Winos, enter nexus-webapp-2.0.2/bin/jsw/windows-x86-32 to run the Nexus.bat script to start the service.

Browser Access site : Http://localhost:8081/nexus

Note:

To change the access port: Modify Nexus-webapp-2.0.2/conf/plexus.properties

(3) Login

Nexus default Administrator and password: admin/admin123

2). Nexus Warehouse and Warehouse Group

Nexus has four types of warehouses: group,hosted,proxy,virtual, warehouse format: Maven2 or MAVEN1, warehouse attribute policy is: Release or snapshot.

3. Set up local maven library steps and some of the problems and solutions you'll encounter with Maven in Eclipse are as follows:

The following is configured in the D:\Java\apache-maven-3.0.1\conf settings.xml file, and Maven's settings.xml is the global setting, which will be used in eclipse to use this custom maven:

1). Set the local MAVEN library address:

<localRepository>D:/Java/maven_repository</localRepository>

2). After setting up the Nexus, set the access server's account and password:

<server>
<id>nexus-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>

3). About Configuring mirroring in Settings.xml

Briefly explain why we need to configure the image, if you do not configure the image, you will find maven default from the Http://repo1.maven.org/maven2 address to download, this is why?

The reasons are as follows: D:\Java\apache-maven-3.0.1\lib\ Maven-model-builder-3.0.1.jar jar Bag You'll find a maven-model-builder-3.0.1.jar\org\apache\maven\model\. Pom-4.0.0.xml file, which specifies the following configuration

<repositories>
<repository>
<id>central</id>
<name>maven Repository switchboard</name>
<url>http://repo1.maven.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>maven Plugin repository</name>
<url>http://repo1.maven.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories>

If you let our native Maven only use the default address for Central warehouse , you need to configure the following image:

<mirror>
<id>Mirror</id>

<!-- if you want to mirror all the warehouses, then add * -
<mirrorOf>*</mirrorOf>
<name>Mirror</name>
<url>http://172.16.101.17:8081/nexus/content/groups/public/</url>
</mirror>

4). In the settings.xml configuration Get dependency packages and plugins as follows:

<profile>
<id>nexus</id>
<repositories>
<repository>
<id>nexus</id>
<name>Nexus</name>
<url>http://172.16.101.17:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<name>Nexus</name>
<url>http://172.16.101.17:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>

5). Configure the above customized maven in eclipse, such as:


6). Project updates in eclipse are dependent on jar packages and system MAVEN configuration methods such as:

7). The following configuration can be set in the Pom file for each project in order to use the MAVEN deployment widget for the local project in the Nexus Library:

<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>nexus releases repository</name>
<url>http://172.16.101.17:8081/nexus/content/repositories/releases/</url>
</repository>

<snapshotRepository>
<id>nexus-snapshots</id>
<name>nexus Snapshots Repository</name>
<url>http://172.16.101.17:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>

4. The following question is a more important issue, as well as a workaround:

I always like to use simple tools, because the development of high efficiency, debugging and check the problem will become very simple, if we usually use myeclipse as a development tool, will be accustomed to use its own integrated Tomcat tool, the version of the low eclipse can only configure TOMCAT6, Can not configure TOMCAT7 and other high version, in fact, this is also a solution, and later.

If we use the MAVEN plugin to develop, some people will use the jetty plug-in or the Tomcat plugin to deploy the application, if the deployment of the application has some problems, such as: we sometimes need to find in the Web container is not successful deployment, and so on, if the use of plug-ins at this time, it may be a bit inconvenient, It would be useful to have a myeclipse integrated tomcat environment, but there is a deployment problem like:

According to MAVEN's structure, the compiled code is placed by default under ${project_name}/target/classes, but the path you deploy to Tomcat is as follows:

So there is a problem, if you modify the project code, the project code will not be updated in real-time to the Web container, for what reason, we should be able to compare the above two graphs can be seen, so we have to solve these default problems, the following:

${project_name}/target/classes will be changed to ${project_name}/src/main/webapp/web-inf/classes, note the map after compiling the class file storage path and other details.

5. Sometimes when we use the MAVEN command to compile or maven install, we may need to skip the testcase test, as follows:

2. Or when using the MVN Install command, add the following parameters:

MVN install-d maven.test.skip=true Note: the addition skips the TestCase test, otherwise the TestCase test is run on install.



Summary of frequently asked questions about using Maven (issues such as using MAVEN, MAVEN project deployment to Tomcat in Eclipse)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.