• maven工程打包成runnable的jar包,拷贝资源和依赖jar包


    eclipse下新建maven工程,生成runnable的jar包。之前一直是手动拷贝依赖的jar包和资源文件,烦得要死。上网可劲查了一下。解决方案如下。
    在pom的配置文件中做如下配置:

    <build>
    		<finalName>...</finalName>
    		<sourceDirectory>src/main/java</sourceDirectory>
    		<resources>
    			<!-- 控制资源文件的拷贝 -->
    			<resource>
    				<directory>src/main/resources</directory>
    				<targetPath>${project.build.directory}</targetPath>
    			</resource>
    		</resources>
    		<plugins>
    			<!-- 设置源文件编码方式 -->
    			<plugin>
    				<groupId>org.apache.maven.plugins</groupId>
    				<artifactId>maven-compiler-plugin</artifactId>
    				<configuration>
    					<defaultLibBundleDir>lib</defaultLibBundleDir>
    					<source>1.6</source>
    					<target>1.6</target>
    					<encoding>UTF-8</encoding>
    				</configuration>
    			</plugin>
    			<!-- 打包jar文件时,配置manifest文件,加入lib包的jar依赖 -->
    			<plugin>
    				<groupId>org.apache.maven.plugins</groupId>
    				<artifactId>maven-jar-plugin</artifactId>
    				<configuration>
    					<archive>
    						<manifest>
    							<addClasspath>true</addClasspath>
    							<classpathPrefix>lib/</classpathPrefix>
    							<mainClass>.....MonitorMain</mainClass>
    						</manifest>
    					</archive>
    				</configuration>
    			</plugin>
    			<!-- 拷贝依赖的jar包到lib目录 -->

    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>2.10</version>
    <executions>
    <execution>
    <id>copy-dependencies</id>
    <phase>package</phase>
    <goals>
    <goal>copy-dependencies</goal>
    </goals>
    <configuration>
    <outputDirectory>${project.build.directory}/lib</outputDirectory>
    <overWriteReleases>false</overWriteReleases>
    <overWriteSnapshots>false</overWriteSnapshots>
    <overWriteIfNewer>true</overWriteIfNewer>
    </configuration>
    </execution>
    </executions>
    </plugin>

    			<!-- 解决资源文件的编码问题 -->
    			<plugin>
    				<groupId>org.apache.maven.plugins</groupId>
    				<artifactId>maven-resources-plugin</artifactId>
    				<version>2.3</version>
    				<configuration>
    					<encoding>UTF-8</encoding>
    				</configuration>
    			</plugin>
    			<!-- 打包source文件为jar文件 -->
    			<plugin>
    				<artifactId>maven-source-plugin</artifactId>
    				<version>2.1</version>
    				<configuration>
    					<attach>true</attach>
    					<encoding>UTF-8</encoding>
    				</configuration>
    				<executions>
    					<execution>
    						<phase>compile</phase>
    						<goals>
    							<goal>jar</goal>
    						</goals>
    					</execution>
    				</executions>
    			</plugin>
    		</plugins>
    	</build>
    
  • 相关阅读:
    Ruby 集合数组常用遍历方法
    Git,Github和Gitlab简介和基本使用
    L1-Day14
    学习进度(2)
    求数组的子数组的最大值(文件存储)
    开学第一课博客——自我介绍
    求数组的子数组的最大值
    学习进度(1)
    java web+模板
    android开发环境配置以及测试所遇到的的问题
  • 原文地址:https://www.cnblogs.com/equation/p/5244477.html
Copyright © 2020-2023  润新知