maven+snoatype nexus+jrebel+eclipse+tomcat整合的小例子

首先安装nexus做为maven的私服:

maven+snoatype nexus+jrebel+eclipse+tomcat整合的小例子

点击install-nexus安装nexus为服务后,访问:http://localhost:8081/nexus/

点击后上角的log in输入默认用户名和密码:admin/admin123,然后点击左侧的菜单repositories,依次单击将右面显示的三个type为proxy的configure中的Download Remote Indexes设置为true;

这么做的目的是同步下载远程索引到本地,以便本地快速搜索。点击保存后依次右键这3个仓库将其repair index。以便更新本地索引。

maven+snoatype nexus+jrebel+eclipse+tomcat整合的小例子

 

 

2,配置maven,关于maven环境变量的设置就不说了。网上有的是。

001 <?xml version="1.0" encoding="UTF-8"?>
002 <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
003           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
004           xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
005   <!-- localRepository
006    | The path to the local repository maven will use to store artifacts.
007    |
008    | Default: ~/.m2/repository-->
009   <localRepository>F:/mvn/repository</localRepository>
010    
011  
012   <!-- interactiveMode
013    | This will determine whether maven prompts you when it needs input. If set to false,
014    | maven will use a sensible default value, perhaps based on some other setting, for
015    | the parameter in question.
016    |
017    | Default: true
018   <interactiveMode>true</interactiveMode>
019   -->
020  
021   <!-- offline
022    | Determines whether maven should attempt to connect to the network when executing a build.
023    | This will have an effect on artifact downloads, artifact deployment, and others.
024    |
025    | Default: false
026   <offline>false</offline>
027   -->
028  
029   <!-- pluginGroups
030    | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
031    | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
032    | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
033    |-->
034   <pluginGroups>
035     <!-- pluginGroup
036      | Specifies a further group identifier to use for plugin lookup.
037     <pluginGroup>com.your.plugins</pluginGroup>
038     -->
039   </pluginGroups>
040  
041   <!-- proxies
042    | This is a list of proxies which can be used on this machine to connect to the network.
043    | Unless otherwise specified (by system property or command-line switch), the first proxy
044    | specification in this list marked as active will be used.
045    |-->
046   <proxies>
047     <!-- proxy
048      | Specification for one proxy, to be used in connecting to the network.
049      |
050     <proxy>
051       <id>optional</id>
052       <active>true</active>
053       <protocol>http</protocol>
054       <username>proxyuser</username>
055       <password>proxypass</password>
056       <host>proxy.host.net</host>
057       <port>80</port>
058       <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
059     </proxy>
060     -->
061   </proxies>
062  
063   <!-- servers
064    | This is a list of authentication profiles, keyed by the server-id used within the system.
065    | Authentication profiles can be used whenever maven must make a connection to a remote server.
066    |-->
067   <servers>
068   <server>
069       <id>nexus-releases</id>
070       <username>admin</username>
071       <password>admin123</password>
072     </server>
073     <server>
074       <id>nexus-snapshots</id>
075       <username>admin</username>
076       <password>admin123</password>
077     </server>
078     <!-- server
079      | Specifies the authentication information to use when connecting to a particular server, identified by
080      | a unique name within the system (referred to by the 'id' attribute below).
081      |
082      | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
083      |       used together.
084      |
085     <server>
086       <id>deploymentRepo</id>
087       <username>repouser</username>
088       <password>repopwd</password>
089     </server>
090     -->
091      
092     <!-- Another sample, using keys to authenticate.
093     <server>
094       <id>siteServer</id>
095       <privateKey>/path/to/private/key</privateKey>
096       <passphrase>optional; leave empty if not used.</passphrase>
097     </server>
098     -->
099   </servers>
100  
101   <!-- mirrors
102    | This is a list of mirrors to be used in downloading artifacts from remote repositories.
103    |
104    | It works like this: a POM may declare a repository to use in resolving certain artifacts.
105    | However, this repository may have problems with heavy traffic at times, so people have mirrored
106    | it to several places.
107    |
108    | That repository definition will have a unique id, so we can create a mirror reference for that
109    | repository, to be used as an alternate download site. The mirror site will be the preferred
110    | server for that repository.
111    |-->
112   <mirrors>
113     <!-- mirror
114      | Specifies a repository mirror site to use instead of a given repository. The repository that
115      | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
116      | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
117      |
118     <mirror>
119       <id>mirrorId</id>
120       <mirrorOf>repositoryId</mirrorOf>
121       <name>Human Readable Name for this Mirror.</name>
122       <url>http://my.repository.com/repo/path</url>
123     </mirror>
124      -->
125      <mirror>
126       <id>nexus</id>
127       <mirrorOf>*</mirrorOf>
128       <name>Nexus Mirror</name>
129       <url>http://localhost:8081/nexus/content/groups/public</url>
130     </mirror>
131   </mirrors>
132    
133   <!-- profiles
134    | This is a list of profiles which can be activated in a variety of ways, and which can modify
135    | the build process. Profiles provided in the settings.xml are intended to provide local machine-
136    | specific paths and repository locations which allow the build to work in the local environment.
137    |
138    | For example, if you have an integration testing plugin - like cactus - that needs to know where
139    | your Tomcat instance is installed, you can provide a variable here such that the variable is
140    | dereferenced during the build process to configure the cactus plugin.
141    |
142    | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
143    | section of this document (settings.xml) - will be discussed later. Another way essentially
144    | relies on the detection of a system property, either matching a particular value for the property,
145    | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
146    | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
147    | Finally, the list of active profiles can be specified directly from the command line.
148    |
149    | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
150    |       repositories, plugin repositories, and free-form properties to be used as configuration
151    |       variables for plugins in the POM.
152    |
153    |-->
154   <profiles>
155   <profile>
156       <id>nexus</id>
157       <repositories>
158         <repository>
159           <id>nexus-releases</id>
160           <name>local private nexus</name>
161           <url>http://localhost:8081/nexus/content/groups/public</url>
162           <releases><enabled>true</enabled></releases>
163           <snapshots><enabled>false</enabled></snapshots>
164         </repository>
165         <repository>
166           <id>nexus-snapshots</id>
167           <name>local private nexus</name>
168           <url>http://localhost:8081/nexus/content/groups/public-snapshots</url>
169           <releases><enabled>false</enabled></releases>
170           <snapshots><enabled>true</enabled></snapshots>
171         </repository>
172       </repositories>
173       <pluginRepositories>
174          <pluginRepository>
175                 <id>nexus-releases</id>
176                  <name>local private nexus</name>
177                  <url>http://localhost:8081/nexus/content/groups/public</url>
178                  <releases><enabled>true</enabled></releases>
179                  <snapshots><enabled>false</enabled></snapshots>
180                </pluginRepository>
181                <pluginRepository>
182                  <id>nexus-snapshots</id>
183                   <name>local private nexus</name>
184                   <url>http://localhost:8081/nexus/content/groups/public-snapshots</url>
185                 <releases><enabled>false</enabled></releases>
186                  <snapshots><enabled>true</enabled></snapshots>
187              </pluginRepository>
188          </pluginRepositories>
189     </profile>
190     <!-- profile
191      | Specifies a set of introductions to the build process, to be activated using one or more of the
192      | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
193      | or the command line, profiles have to have an ID that is unique.
194      |
195      | An encouraged best practice for profile identification is to use a consistent naming convention
196      | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
197      | This will make it more intuitive to understand what the set of introduced profiles is attempting
198      | to accomplish, particularly when you only have a list of profile id's for debug.
199      |
200      | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
201     <profile>
202       <id>jdk-1.4</id>
203  
204       <activation>
205         <jdk>1.4</jdk>
206       </activation>
207  
208       <repositories>
209         <repository>
210           <id>jdk14</id>
211           <name>Repository for JDK 1.4 builds</name>
212           <url>http://www.myhost.com/maven/jdk14</url>
213           <layout>default</layout>
214           <snapshotPolicy>always</snapshotPolicy>
215         </repository>
216       </repositories>
217     </profile>
218     -->
219  
220     <!--
221      | Here is another profile, activated by the system property 'target-env' with a value of 'dev',
222      | which provides a specific path to the Tomcat instance. To use this, your plugin configuration
223      | might hypothetically look like:
224      |
225      | ...
226      | <plugin>
227      |   <groupId>org.myco.myplugins</groupId>
228      |   <artifactId>myplugin</artifactId>
229      |  
230      |   <configuration>
231      |     <tomcatLocation>${tomcatPath}</tomcatLocation>
232      |   </configuration>
233      | </plugin>
234      | ...
235      |
236      | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
237      |       anything, you could just leave off the <value/> inside the activation-property.
238      |
239     <profile>
240       <id>env-dev</id>
241  
242       <activation>
243         <property>
244           <name>target-env</name>
245           <value>dev</value>
246         </property>
247       </activation>
248  
249       <properties>
250         <tomcatPath>/path/to/tomcat/instance</tomcatPath>
251       </properties>
252     </profile>
253     -->
254   </profiles>
255  
256   <!-- activeProfiles
257    | List of profiles that are active for all builds.
258    |
259   <activeProfiles>
260     <activeProfile>alwaysActiveProfile</activeProfile>
261     <activeProfile>anotherAlwaysActiveProfile</activeProfile>
262   </activeProfiles>
263   -->
264   <activeProfiles>
265     <activeProfile>nexus</activeProfile>
266   </activeProfiles>
267 </settings>

主要是配置repository。它的ID对应的是maven中的repository.以便maven能使用nexus搜索和管理组件,极大节约带宽,加速开发。

maven的配置如下:

01 <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">
02     <modelVersion>4.0.0</modelVersion>
03     <groupId>com.tudou</groupId>
04     <artifactId>tudouSystem</artifactId>
05     <packaging>war</packaging>
06     <version>0.0.1-SNAPSHOT</version>
07     <name>tudouSystem Maven Webapp</name>
08     <!--<url>http://maven.apache.org</url> -->
09     <properties>
10         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
11         <tomcatPath>D:\progra\tomcat6</tomcatPath>
12     </properties>
13     <distributionManagement>
14         <repository>
15             <id>nexus-releases</id>
16             <name>Nexus Release Repository</name>
17             <url>http://localhost:8081/nexus/content/repositories/releases/</url>
18         </repository>
19         <snapshotRepository>
20             <id>nexus-snapshots</id>
21             <name>Nexus Snapshot Repository</name>
22             <url>http://localhost:8081/nexus/content/repositories/snapshots/
23             </url>
24         </snapshotRepository>
25     </distributionManagement>
26     <dependencies>
27         <dependency>
28             <groupId>javax.servlet</groupId>
29             <artifactId>javax.servlet-api</artifactId>
30             <version>3.0.1</version>
31         </dependency>
32     </dependencies>
33     <build>
34         <plugins>
35             <!-- Run As Maven build : clean package 就可以发布到tomcat下了,并按照<warName>命名 访问应用时,访问该地址即可:http://IP:Port/warName/ -->
36             <plugin>
37                 <artifactId>maven-war-plugin</artifactId>
38                 <version>2.2</version>
39                 <configuration>
40                     <!--默认打包名为项目名称,生成的WAR存放在target下-->
41                     <warName>tudouSystem</warName>
42                     <outputDirectory>${tomcatPath}\webapps</outputDirectory>
43                     <!--修改JSP文件后不能重新编译发布-->
44                     <webappDirectory>${basedir}/src/main/webapp</webappDirectory>
45                     <warSourceDirectory>${basedir}/src/main/webapp</warSourceDirectory>
46                 </configuration>
47             </plugin>
48         </plugins>
49     </build>
50 </project>
3,建立你的maven项目。完整的项目结构如图所示,注意它的default-output

maven+snoatype nexus+jrebel+eclipse+tomcat整合的小例子

这是还必须配置tomcat,<Context docBase="E:\java\newwork\tudouSystem\src\main\webapp" path="/tudouSystem" reloadable="false" />

项目的WEB.XML

01 <?xml version="1.0" encoding="UTF-8"?>
02 <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
03     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
04     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee  
05     http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
06     <servlet>
07         <servlet-name>TestServlet</servlet-name>
08         <servlet-class>com.tudou.web.servlet.TestServlet</servlet-class>
09     </servlet>
10     <servlet-mapping>
11         <servlet-name>TestServlet</servlet-name>
12         <url-pattern>/TestServlet</url-pattern>
13     </servlet-mapping>
14  
15     <welcome-file-list>
16         <welcome-file>/TestServlet</welcome-file>
17     </welcome-file-list>
18     <display-name>Archetype Created Web Application</display-name>
19 </web-app>
项目的servlet:

package com.tudou.web.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @className:TestServlet.java
 * @classDescription:
 * @author:很拽の土豆
 * @createTime:2012-8-25 上午4:31:48
 */
public class TestServlet extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		this.doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setAttribute("YouName", "很拽の土豆");
		req.getRequestDispatcher("/index.jsp").forward(req, resp);
	}
}

JSP页面:

01 <%@ page language="java" contentType="text/html; charset=UTF-8"
02     pageEncoding="UTF-8"%>
03 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
04 <html>
05 <head>
06 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
07 <title>Insert title here</title>
08 </head>
09 <body>
10 <h2>欢迎:${YouName}</h2>
11 </body>
12 </html>

右键:debug as ->maven clean ->package这是项目可以正常访问了。但是修改Servlet后必须重启服务。

3,安装jrebel

eclipse菜单help->eclipse market->install jrebel。next安装完之后会提示你重启。此时不要重启。因为jrebel是付费版。下载破解版jrebel.jar5.0。在eclipse/plugins下面搜索jrebel.jar然后定位到其所在的文件夹,复制进去覆盖。启动eclipse后选中项目debug as ->debug configurion,点击apache tomcat后会看到最后面的jrebel,勾选enabled jrebel。点击run.

maven+snoatype nexus+jrebel+eclipse+tomcat整合的小例子

此时修改servlet后发现不用重启tomcat了~!~~~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值