为 clojure 源文件启用 UTF-8 编码 [英] enabling UTF-8 encoding for clojure source files

查看:28
本文介绍了为 clojure 源文件启用 UTF-8 编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个涉及 maven、java 和 clojure 的项目.我面临的问题是,我的 clojure 源文件中有一些 UTF-8 字符,因为我的源代码没有被 java 编译器正确解释,我有点通过设置让它工作环境变量 JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8,但我想要的是通过 MAVEN 传递这个属性.

I'm working on a project which involves maven, java and clojure. The problem I'm facing is this, I have some UTF-8 chars in my clojure source files because of which my source code is not interpreted correctly by the java compiler, I kinda got it working by setting the environment variable JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8, but what I want is to pass this property through MAVEN.

我已经尝试过设置 MAVEN_OPTS=-Dfile.encoding 但这似乎不起作用.
我也尝试过为 maven 的编译器插件设置配置......像这样:

I have already tried setting MAVEN_OPTS=-Dfile.encoding but this doesn't seem to work.
I have also tried setting configuration for the compiler plugin of maven... something like this:

 <configuration>
        <compilerArgument>-Dfile.encoding=UTF8</compilerArgument>
 </configuration>

这也不起作用.

我做错了什么,还是有其他方法.

I'm I doing something wrong, or is there another way.

谢谢,
研发

好的,这里有更多细节.这是我的父 pom,

Ok, Here's some more detail. This is my parent pom,

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
      <source>1.5</source>
      <target>1.5</target>
      <encoding>UTF-8</encoding> <! also tried <encoding>UTF8</encoding>
    </configuration>
  </plugin>

孩子的 pom 没有什么有趣的,除了......

Nothing interesting in the child's pom except...

<resources>
  <resource>
    <directory>src/main/clojure</directory>
  </resource>
</resources>

;;导致问题的 clojure 代码片段

;; clojure code snippet which causes problems

(let [char "대"]
   (not (empty? (filter #(s/contains? % char) <some-list>)))
;; The list is always empty because I never find a match if I do not set the env. variable

推荐答案

更新:根据您的评论,这是一个运行时问题,而不是编译问题.作为一种解决方法,您可以尝试将字符转义为 unicode.

Update: Based on your comments, this is a runtime, not a compile issue. As a workaround, you could try escaping the character as unicode.

即将clojure文件中的字符改为'uXXXX',其中XXXX是16进制的Unicode点.

i.e. change the character to 'uXXXX' in the clojure file, where XXXX is the Unicode point in hexadecimal.

如果您的问题发生在单元测试中.您可以通过设置 argLine 属性.这允许您在命令行上设置任意 JVM 选项.

If your problem is happening in your unit tests. You can configure the surefire plugin by setting the argLine property. This allows you to set arbitrary JVM options on the command line.

这篇关于为 clojure 源文件启用 UTF-8 编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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