Maven默认语言环境与OS语言环境不同 [英] Maven default locale not same with OS locale

查看:142
本文介绍了Maven默认语言环境与OS语言环境不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我输入

mvn --version

在命令提示符下,我看到:

in command prompt I see:

默认语言环境:en_US

Default Locale : en_US

但是我的系统语言环境是tr_TR

However my System Locale is tr_TR

当我启动不带maven的Java SE Project并运行Locale.getDefault()tr_TR会返回正常.但是当我运行一个Maven项目,然后运行Locale.getDefault()时,它返回我不喜欢的en_US.

When I start a Java SE Project without maven and run Locale.getDefault() tr_TR returns fine. But when I run a Maven project and then Locale.getDefault() it returns en_US which I do not like.

如何告诉Maven我的默认语言环境是TR?

How can I tell maven that my default locale is TR ?

推荐答案

您可以使用此命令

set MAVEN_OPTS= -Duser.language=tr

无论如何,最好的解决方案是将这些信息存储在POM文件中,而不是通过命令行存储.特别是,您必须处理 Maven-Surefire-Plugin 的配置 a>

Anyway the best solution is to put these informations in the POM file and never by command line. In particular you have to deal with the configuration of Maven-Surefire-Plugin

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.9</version>
        <configuration>
            <systemPropertyVariables>
                <user.language>tr</user.language>
                <user.region>TR</user.region>
            </systemPropertyVariables>
        </configuration> 
    </plugin>

第二个问题: 如果可能的话,我要问的另一个问题是,我在自己的语言环境中运行一个Web应用程序,但它支持说德语,英语..而您的系统语言环境是DE.我可以从您的请求中获取您的系统语言环境吗?还是您浏览器更喜欢的语言?

Second Question: Another question if I may, I am running a web app in my locale but it supports lets say german, english.. And your system locale is DE. Can I get your system locale from your request? Or maybe the language you prefer by your browser?

您可以从请求中获取这些信息.这是servlet中的示例.

You can take these informations from the request. Here is an example in a servlet.

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.Locale;

public class GetLocale extends HttpServlet{

  public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException, IOException
  {
      Locale locale = request.getLocale();
      String language = locale.getLanguage();
      String country = locale.getCountry();

      response.setContentType("text/html");
      PrintWriter out = response.getWriter();

      out.println(language + ":" + country);
  }
}

这篇关于Maven默认语言环境与OS语言环境不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆