Maven default locale not same with OS locale

前端 未结 3 2142
天涯浪人
天涯浪人 2021-02-20 06:44

When I type

mvn --version

in command prompt I see:

Default Locale : en_US

However my System Loca

3条回答
  •  [愿得一人]
    2021-02-20 07:02

    You can use this command

    set MAVEN_OPTS= -Duser.language=tr
    

    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

        
            org.apache.maven.plugins
            maven-surefire-plugin
            2.9
            
                
                    tr
                    TR
                
             
        
    

    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?

    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);
      }
    }
    

提交回复
热议问题