maven打包编译java类时指定jdk版本和编码格式

来源:互联网 发布:网购电影票软件 编辑:程序博客网 时间:2024/05/17 21:07

1、指定jdk版本:

<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>default-jar</id>
<phase>package</phase>
<configuration>
<includes>
<classesDirectory>com/**</classesDirectory>
</includes>
</configuration>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<encoding>GBK</encoding>
<source>1.6</source>
<target>1.6</target>
<debug>true</debug>
</configuration>
</plugin>
</plugins>
</build>


2、指定编译的class编码格式:

<properties>
         <project.build.sourceEncoding>
             GBK
         </project.build.sourceEncoding>
</properties>


用ant打包可以看到编码格式被修改过来了:

[artifact:mvn] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ gaia-service ---
[artifact:mvn] [INFO] Using 'GBK' encoding to copy filtered resources.
[artifact:mvn] [INFO] Copying 1 resource
[artifact:mvn] [INFO] Copying 26 resources

原创粉丝点击