Using Maven to create eclipse (indigo) as myeclipse

Source: Internet
Author: User

I have been using myeclipse for a J2EE website, but it is not an HTML, CSS, or js code prompt or webpage editing in the form of "What you see is what you get, she prefers convenient website deployment and server operations. However, every time myeclipse is installed, it requires cracking, which leaves a shadow in your mood. I always feel that I am doing bad things, so I feel uneasy ...... Finally, I took the courage to go to the eclipse official website to find a J2EE version of eclipse indigo. Although I can make it look like myeclipse through eclipse's own configuration, it is still not flexible after all, many operations must be manually completed during development.

Is there a way to make eclipse more automated when developing J2EE projects? Of course! Maven is used!

This article uses Maven's resources, antrun, clean, war and other plug-ins to implement:

1. Compile Servlet

2. Generate a war File

3. Generate the website directory structure

4. Website deployment

5. Anti-deployment of websites

6. redeploy the website

7. Start the server

8. Disable the server

9. 1. Generate a website-deploy a website-start a server

......

What's more, after Maven is used, continuous integration can be easily completed with Hudson!

The most important thing to implement the above functions is the POM file. below is the code of the POM file:

<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/maven-v4_0_0.xsd"> <modelversion> 4.0.0 </modelversion> <groupid> cn.edu. SDU. ise. leesonlog. lms4g </groupid> <artifactid> lms4g-website </artifactid> <packaging> war </packaging> <version> 0.0.1-Snapshot </version> <Name> lms4g-we Bsite Maven webapp </Name> <URL> http://maven.apache.org </URL> <Properties> <SERVER_NAME> tomcat7x </SERVER_NAME> <server_home> D: \ apache-Tomcat-7.0.25 </server_home> <server_disk> D: </server_disk> <project_web1__directory >$ {server_home}/webapps/$ {project. build. finalname} </project_webpai_directory> </Properties> <dependencies> <dependency> <groupid> JUnit </groupid> <artifactid> JUnit </artifactid> <versi On> 3.8.1 </version> <scope> test </scope> </dependency> <groupid> Tomcat </groupid> <artifactid> servlet-API </artifactid> <version> 5.5.23 </version> <scope> compile </scope> </dependency> </dependencies> <build> <! -- Set the plug-in version --> <pluginmanagement> <plugins> <plugin> <artifactid> Maven-antrun-plugin </artifactid> <version> 1.7 </version> </plugin> <plugin> <artifactid> Maven-clean-plugin </artifactid> <version> 2.4.1 </version> </plugin> <artifactid> Maven-resources-plugin </artifactid> <version> 2.5 </version> </plugin> </plugins> </pluginmanagement> <finalname> lms4g </finalname> <resources> <! -- Filter the Resources Directory, mainly set the content in the bat directory --> <resource> <directory >$ {project. basedir}/src/main/resources </directory> <filtering> true </filtering> </resource> </resources> <plugins> <plugin> <artifactid> Maven-surefire -plugin </artifactid> <configuration> <skiptests> true </skiptests> </configuration> </plugin> </plugins> </build> <profiles> <! -- Start Tomcat server --> <profile> <ID> startup-server </ID> <build> <plugins> <plugin> <artifactid> Maven-antrun-plugin </artifactid> <configuration> <tasks> <exec executable = "$ {project. build. outputdirectory}/BAT/mystartup. bat "> </exec> </tasks> </configuration> </plugin> </plugins> </build> </profile> <! -- Disable Tomcat server --> <profile> <ID> shutdown-server </ID> <build> <plugins> <plugin> <artifactid> Maven-antrun-plugin </artifactid> <configuration> <tasks> <exec executable = "$ {project. build. outputdirectory}/BAT/myshutdown. bat "> </exec> </tasks> </configuration> </plugin> </plugins> </build> </profile> <! -- Clear or deploy the website on the server --> <profile> <ID> modify-webapps </ID> <build> <plugins> <! -- Use the clean plug-in to clear webapps website directories and war files --> <plugin> <artifactid> Maven-clean-plugin </artifactid> <configuration> <verbose> false </verbose> <filesets> <fileset> <directory >$ {server_home}/webapps </directory> <supported des> <include >$ {project. build. finalname }. war </include> </Includes> </fileset> <directory >$ {project_web1__directory} </directory> </fileset> </filesets> <! -- Do not delete the default output directory of the project --> <excludedefadirectdirectories> true </excludedefadirectdirectories> </configuration> </plugin> <! -- Use the resources plug-in to copy website files to webapps on the server. You must run the MVN command separately Instead of binding them to the default phase (phase) --> <plugin> <artifactid> Maven-resources-plugin </artifactid> <configuration> <outputdirectory >$ {project_webpai_directory} </outputdirectory> <resources> <resource> <directory> $ {project. build. directory}/$ {project. build. finalname} </directory> </resource> </resources> <shortdeemptydirs> true </shortdeemptydirs> <encoding> UTF-8 </encoding> </configuration> </plugin> </ plugins> </build> </profile> </profiles> </Project>

The directory structure of the project is as follows:

The code for the two BAT files used to start and shut down the server is as follows:

Mystartup. BAT file:

${server_disk}cd ${server_home}/binstartup.bat

Myshutdown. BAT file:

${server_disk}cd ${server_home}/binshutdown.bat

The following describes how to implement the functions listed at the beginning.

1. Compile Servlet

This is the easiest way to directly use the maven-compile-plugin plug-in, that is, to run the command in the command line or m2e plug-in:

mvn compile

2. Generate a war File

To generate a war file, you must set the <packaging> attribute of the project to war, and then use the maven-war-plugin plug-in to run the command in the command line or m2e plug-in:

mvn package

3. Generate the website directory structure

When generating the war file, you may notice that Maven has actually generated the $ {finalname} folder under the target directory, which is the website directory that can be deployed on the server.

However, in the package phase (phase), in addition to the website directory, the war file is also generated, which may be redundant in the debugging phase, that is, we do not need to generate a war file, it takes time to generate and deploy resources (because the server needs to decompress the war file). Why!

So we need Maven to generate only the project's website directory. during deployment, copy the website directory directly to the wabapps directory on the server, saving time for packaging and decompressing war files!

In fact, for a Maven project whose <packaging> attribute is war, the package phase (phase) uses the maven-war-plugin war target (goal ), you can see from the help page of the maven-war-plugin plug-in that the plug-in actually has an exploded target (GOAL), which only generates the website directory, instead of packaging it into a war file, we just want it!

(Unfinished, To be continued ......)

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.