maven項目打成 jar 包(含有webService)

本項目的開發工具是Eclipse


一、pom.xml 配置

注意:

要加 <defaultGoal>compile</defaultGoal>

eclipse安裝的maven插件是m2eclipse,在控制檯使用命令mvn compile並未報錯。後在pom.xml文件標籤裏面加 上compile即可。 其實使用命令行時就已經指定了phase,而使用m2eclipse的【Run As】-【Maven build】時並未爲其指定goal或phase,所以才報錯

<!-- 用於打包 -->
	<build>
	<defaultGoal>compile</defaultGoal>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <archive>
                        <manifest>
                            <!-- 我運行這個jar所運行的主類 -->
                            <mainClass>com.ydtf.ipcc.sms.service.SmsTimerTask</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>
                            <!-- 必須是這樣寫 -->
                            jar-with-dependencies
                        </descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>
        </plugins>
    </build>

因爲引用了webService接口中方法,所以加了下面配置:

注意:有的不用加,也不知道爲什麼

                <!-- 生成webService客戶端 -->
		<dependency>
			<groupId>axis</groupId>
			<artifactId>axis</artifactId>
			<version>1.4</version>
			<scope>compile</scope>
			<optional>true</optional>
		</dependency>


二、利用 maven 打包

第一步:右鍵項目,選擇 Run As  ——> Maven build ..  ——> 添加參數 assembly:assembly



第二步:右鍵項目,選擇 Run As  ——> Maven install


打包成功後在 target 文件夾下生成 jar包,如圖:



三、在 cmd 中運行

java -jar xxxx(jar包名稱)




發佈了55 篇原創文章 · 獲贊 16 · 訪問量 12萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章