关闭

maven常用配置

标签: maven依赖包maven常用配置war相互依赖编译时找不到类
119人阅读 评论(0) 收藏 举报
分类:
  1. 把依赖的jar包打包到lib目录下:
    <plugin>
    	<groupId>org.apache.maven.plugins</groupId>
    	<artifactId>maven-dependency-plugin</artifactId>
    	<executions>
    		<execution>
    			<id>copy-dependencies</id>
    			<phase>package</phase>
    			<goals>
    				<goal>copy-dependencies</goal>
    			</goals>
    			<configuration>
    				<outputDirectory>${project.build.directory}/lib</outputDirectory>
    				<overWriteReleases>true</overWriteReleases>
    				<overWriteSnapshots>true</overWriteSnapshots>
    				<overWriteIfNewer>true</overWriteIfNewer>
    			</configuration>
    		</execution>
    	</executions>
    </plugin>
  2. 清单文件MANIFEST.MF中加入main方法、依赖包classpath:
    <plugin>
    	<groupId>org.apache.maven.plugins</groupId>
    	<artifactId>maven-jar-plugin</artifactId>
    	<configuration>
    		<archive>
    			<manifest>
    				<addClasspath>true</addClasspath>
    				<mainClass>client.App</mainClass>
    				<classpathPrefix>lib</classpathPrefix>  
    			</manifest>
    		</archive>
    	</configuration>
    </plugin>

  3. maven中加入本地jar:
    <dependency>
    	<groupId>org.safehaus.jug</groupId>
    	<artifactId>jug</artifactId>
    	<version>2.0.0</version>
    	<scope>system</scope>  
    	<!--本地jar的路径,相对或者绝对都可以 -->
    	<systemPath>${basedir}/lib/jug-2.0.0-asl.jar</systemPath>
    </dependency>

  4. war项目相互依赖,eclipse在编译时找不到类的处理
    1. <!-- 被依赖的项目中加入maven-jar-plugin将类单独打一个类jar -->
      <plugin>
      	<groupId>org.apache.maven.plugins</groupId>
      	<artifactId>maven-jar-plugin</artifactId>
      	<version>2.6</version>
      	<executions>
      		<execution>
      			<goals>
      				<goal>jar</goal>
      			</goals>
      		</execution>
      	</executions>
      	<configuration>
      		<classifier>classes</classifier>
      	</configuration>
      </plugin>
      
      
    2. <pre name="code" class="html"><!-- 依赖项目中除了加入web依赖,再加入类包依赖 -->
      <dependency>
      	<groupId>w1</groupId>
      	<artifactId>w1</artifactId>
      	<version>0.0.1-SNAPSHOT</version>
      	<type>war</type>
      </dependency>
      <dependency>
      	<groupId>w1</groupId>
      	<artifactId>w1</artifactId>
      	<version>0.0.1-SNAPSHOT</version>
      	<classifier>classes</classifier>
      	<scope>test</scope>
      </dependency>
  5. 导出jar包源码
               <plugin>  
                    <artifactId>maven-source-plugin</artifactId>  
                    <version>2.4</version>  
                    <configuration>  
                        <attach>true</attach>  
                    </configuration>  
                    <executions>  
                        <execution>  
                            <phase>compile</phase>  
                            <goals>  
                                <goal>jar</goal>  
                            </goals>  
                        </execution>  
                    </executions>  
                </plugin>

  6. 待续。

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:902次
    • 积分:30
    • 等级:
    • 排名:千里之外
    • 原创:2篇
    • 转载:1篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档