如何解决maven错误:java.lang.NullPointerException:charsetName whean

时间:2015-11-19 18:13:53

标签: java maven

我尝试为我的项目执行mvn package,但总是得到错误。

在我的 pom.xml 中添加了以下属性:

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.resources.sourceEncoding>UTF-8</project.resources.sourceEncoding>
</properties>
...
<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
            <outputEncoding>UTF-8</outputEncoding>
            <argLine>-Dfile.encoding=UTF-8</argLine>
            <encoding>${project.build.sourceEncoding}</encoding>
            <source>1.5</source>
            <target>1.5</target>
        </configuration>
        <version>3.0</version>
</plugin>

并运行>mvn package -Dfile.encoding=UTF-8,但没有成功:

java.lang.NullPointerException: charsetName
    at java.io.OutputStreamWriter.<init>(OutputStreamWriter.java:99)
    at org.apache.jasper.compiler.JDTJavaCompiler.getJavaWriter(JDTJavaCompiler.java:120)
    at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:146)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:362)
    at org.apache.jasper.JspC.processFile(JspC.java:1137)
    at org.apache.jasper.JspC.execute(JspC.java:1306)
    at com.reucon.maven.plugin.openfire.jspc.JspcMojo.compile(JspcMojo.java:279)
    at com.reucon.maven.plugin.openfire.jspc.JspcMojo.execute(JspcMojo.java:196)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

错误抛出此代码:

public OutputStreamWriter(OutputStream out, String charsetName) throws UnsupportedEncodingException {
    super(out);
    if (charsetName == null)
        throw new NullPointerException("charsetName");
    se = StreamEncoder.forOutputStreamWriter(out, this, charsetName);
}

请帮我解决错误。我已经失去了5个小时。

此问题不会重复it,因为我查询了maven。

感谢您提前!

1 个答案:

答案 0 :(得分:0)

将javaEncoding元素放在pom.xml中

 <plugin>
    <groupId>com.reucon.maven.plugins</groupId>
    <artifactId>maven-openfire-plugin</artifactId>
    <extensions>true</extensions>
    <configuration>
      <javaEncoding>UTF-8</javaEncoding>
    </configuration>
    <version>1.0.2-SNAPSHOT</version>
  </plugin>