问题描述
我正在开发一个涉及maven,java和clojure的项目。我面临的问题是,我有一些 UTF-8
字符在我的clojure源文件,因为我的源代码不能被Java编译器正确解释,我kindal通过设置环境变量 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.
感谢,
RD
thanks,
RD
好的,
这是我的父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是十六进制的Unicode点。
i.e. change the character to '\uXXXX' in the clojure file, where XXXX is the Unicode point in hexadecimal.
如果你的问题发生在你的单元测试中,你可以通过设置。这允许您在命令行上设置任意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编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!