本項目的開發工具是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包名稱)