周梦康 发表于 2016-01-02 4424 次浏览 标签 : maven

我使用 Intellij 默认的打包命令是

/Library/Java/JavaVirtualMachines/jdk1.8.0_66.jdk/Contents/Home/bin/java "-Dmaven.home=/Applications/IntelliJ IDEA 14.app/Contents/plugins/maven/lib/maven3" "-Dclassworlds.conf=/Applications/IntelliJ IDEA 14.app/Contents/plugins/maven/lib/maven3/bin/m2.conf" -Didea.launcher.port=7543 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA 14.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/Applications/IntelliJ IDEA 14.app/Contents/plugins/maven/lib/maven3/boot/plexus-classworlds-2.4.jar:/Applications/IntelliJ IDEA 14.app/Contents/lib/idea_rt.jar" com.intellij.rt.execution.application.AppMain org.codehaus.classworlds.Launcher -Didea.version=14.1 package

运行信息如下

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building netty-light-api-server 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ netty-light-api-server ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ netty-light-api-server ---
[INFO] Compiling 19 source files to /Users/zhoumengkang/Documents/coding/github/netty-light-api-server/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /Users/zhoumengkang/Documents/coding/github/netty-light-api-server/src/main/java/net/mengkang/api/route/ApiRoute.java:[55,31] 错误: -source 1.5 中不支持 switch 中存在字符串
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.712s
[INFO] Finished at: Sat Jan 02 20:15:41 CST 2016
[INFO] Final Memory: 14M/220M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project netty-light-api-server: Compilation failure
[ERROR] /Users/zhoumengkang/Documents/coding/github/netty-light-api-server/src/main/java/net/mengkang/api/route/ApiRoute.java:[55,31] 错误: -source 1.5 中不支持 switch 中存在字符串
[ERROR] -> [Help 1]

不知道为什么这里是默认会把我java 1.8 的项目打包成 java 1.5 的。

可以在pom.xml配置下即可。

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <encoding>${project.build.sourceEncoding}</encoding>
            </configuration>
        </plugin>
    </plugins>
</build>

上面的${project.build.sourceEncoding}定义的字符集

👇 下面是我的公众号,高质量的博文我会第一时间同步到公众号,给个关注吧!

评论列表