eclipse maven tomcat 虚拟目录 多资源文件夹 多源码文件夹

格式来点吧。

1.以前使用eclipse + tomcate 开发j2ee,直接使用虚拟目录,很爽,揪其爽处主要在于,eclipse和tomcate共用同一份代码,出现莫名其妙的问题机会很少,这是相比于在复制一份项目文件发布到tomcate,有利有弊,有些人经常新建项目就需要多写几个

<Context docBase="F:/OpenSource" debug="0" privileged="true"   reloadable="true"></Context>

2.现在使用maven 自动寻找jar包,很方便,问题也来了,不能使用tomcate虚拟目录,使用eclipse的run as  ? no no ,我很怀旧。

解决方法,将maven编译的class放入到  WebContent\WEB-INF\classes

             

<build>
    <defaultGoal>compile</defaultGoal>
     <outputDirectory>WebContent/WEB-INF/classes</outputDirectory>
//................................

     将maven的jar 复制到对应的 web-inf\lib

		<!-- 处理依赖jar -->
		 <plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-dependency-plugin</artifactId>
			<version>2.1</version>
			<executions>
				<execution>
					<id>copy</id>
					<phase>compile</phase>
					<goals>
						<goal>copy-dependencies</goal>
					</goals>
					<configuration>
						<outputDirectory>WebContent/WEB-INF/lib</outputDirectory>
						 <excludeTransitive>false</excludeTransitive>
          				 <stripVersion>true</stripVersion>
					</configuration>
				</execution>
			</executions>
		</plugin>

这样,右键 run as maven bulid ,就生成了,有了齐全的目录,tomcate还无法运行么?也就不需要eclipse的复制副本发布了。

----------------------------------------------------------------------------------------------

另一个问题,源码分类,有用包管理的,我喜欢用source filder ,当然是区分不同知识点又不想建立一大堆工程。这在maven下也很好解决。

首先,屏蔽掉

		
<!-- 可以配置多个资源文件 这里不使用
<sourceDirectory>src</sourceDirectory>
<resources>
	<resource>
		<directory>src</directory>
	</resource>
	<resource>
		<directory>01_helloStruts2</directory>
		<filtering>true</filtering>
		<excludes>
			<exclude>**/*.java</exclude>
		</excludes>
	</resource>
</resources>
-->
		
		

其次,使用插件            pom.rar (1.4 KB)

	<!-- 处理多个源文件夹,资源文件夹 -->
	<plugin>
		<groupId>org.codehaus.mojo</groupId>
		<artifactId>build-helper-maven-plugin</artifactId>
		<version>1.12</version>
		<executions>
			<execution>
				<id>add-source</id>
				<phase>generate-sources</phase>
				<goals>
					<goal>add-source</goal>
				</goals>
				<configuration>
					<sources>
						<source>${basedir}/src</source>
						<source>${basedir}/01_helloStruts2</source>
						<!-- 我们可以通过在这里添加多个source节点,来添加任意多个源文件夹 -->
					</sources>
				</configuration>
			</execution>
		
			<execution> <!--处理资源文件,只留作记录,不好用,不如使用eclipse的自动生成 -->
				<id>add-resource</id>  
				<phase>generate-sources</phase>  
				<goals>
					<goal>add-resource</goal>
				</goals>
				<configuration>
					<resources> 
						<resource>
							<directory>src</directory>  
							<directory>${basedir}/01_helloStruts2</directory>
							<!-- 我们可以通过在这里添加多个resource节点,但是得有包,没有包不会自动添加,此功添加资源法不如直接使用eclipse的自动编译会复制   -->
							<filtering>true</filtering> 
							<excludes>
								<exclude>**/*.java</exclude>
							</excludes>
						</resource>
					</resources>
				</configuration>
			</execution>
			
			
		</executions>
	</plugin>

感觉不错了,其实,有几个问题需要注意下,第一,测试的时候,发现如果是空的源文件,无法正常add-resource,不过这都不是问题,正好利用了eclipse的自动编译,maven可以编译,eclipse也可以编译,maven编译不复制资源文件,那就用eclipse的了,不影响开发。

第二个问题,好了,忘了。。

另有一个关于那个插件报错,其实两种解决,第一个是添加

解决 maven 插件报错 
1.eclipse的安装目录下的plugins下的org.eclipse.m2e.lifecyclemapping.defaults_xxxxxx.jar   -   lifecycle-mapping-metadata.xml

添加如下
添加这个标签(不建议)

 <pluginManagement>
        <plugins> </plugins>

另一个,下载附件
lifecycle-mapping-metadata.rar (1.1 KB)

2. Window-Perferences-Maven-Lifecycle Mapping  ,选择添加后的文件(附件) lifecycle-mapping-metadata.xml

上图吧。。



 



 



 

猜你喜欢

转载自tianshu.iteye.com/blog/2319200