13

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.

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>

This doesn't work either.

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

thanks,
RD

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>

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

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

;; 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
RD.
  • 300
  • 4
  • 12

6 Answers6

1

Did you try passing compiler options? [-encoding UTF-8]

alphazero
  • 27,094
  • 3
  • 30
  • 26
  • Actually I did,... (I did mentioned it in the top, but somehow it did not get printed. Let me try again) -Dfile.encoding=UTF8 – RD. Sep 16 '09 at 05:21
1

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

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

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.

Rich Seller
  • 83,208
  • 23
  • 172
  • 177
  • Hi Rich, I'm not compiling the clojure files (as in to generate a class). I'm calling clojure code like this RT.var(, ).invoke(args*). More importantly, the code works if I set the JAVA_TOOL_OPTIONS to -Dfile.encoding=UTF8. Specically, my clojure source file has an UTF-8 char, which I try to match with another char read from a String. If the JAVA_TOOL_OPTIONS is not set, the match never happens. – RD. Sep 16 '09 at 13:32
  • @RD are you able to update your question with some more detail, perhaps a simplified POM and the files that you're getting the problem with. – Rich Seller Sep 16 '09 at 13:34
  • @RD thanks for the update, my Clojure skills approach 0, so sorry for all the questions. If I may summarise, you have a clojure (.clj?) source file in src/main/clojure, this file is copied into target/classes during the process resources file, then you invoke it from within some java code by calling on the RT type you mention above? – Rich Seller Sep 16 '09 at 17:01
  • +1 for configuring argLine property for surefire. My problem lies in unit tests file encoding which should be configured via surefire plugin. – nybon Feb 21 '13 at 08:00
0

Did you set the parameter through Compiler Plugin like this?

<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
      <compilerArgument>-Dfile.encoding=UTF8</compilerArgument>
    </configuration>
  </plugin>
</plugins>
ZZ Coder
  • 74,484
  • 29
  • 137
  • 169
  • yes I have tried exaclty like that (though this conf. is in a parent pom), but no luck. – RD. Sep 16 '09 at 06:05
0

Given the fact that Clojure actually hardcodes the expected encoding of input files to UTF8 (see src/jvm/clojure/lang/Compiler.java, loadFile-method), I'm surprised that using file.encoding does have any effect at all.

pmf
  • 7,619
  • 4
  • 47
  • 77
  • pmf, thanks for the info, I'll try posting this question to the clojure group and see what happens. – RD. Sep 17 '09 at 01:35
0

Try adding this property to your pom UTF-8

0

For me, this code works without problem in cider REPL in Emacs.

;; returns sequence ("대")
(filter #(= % "대") ["대" "한" "민" "국"])

Can you provide code which emits error?

chunsj
  • 199
  • 1
  • 9