RD.
RD.

Reputation: 330

enabling UTF-8 encoding for clojure source files

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

Upvotes: 13

Views: 5537

Answers (6)

chunsj
chunsj

Reputation: 309

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

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

Can you provide code which emits error?

Upvotes: 0

user185241
user185241

Reputation:

Try adding this property to your pom UTF-8

Upvotes: 0

Rich Seller
Rich Seller

Reputation: 84038

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.

Upvotes: 1

pmf
pmf

Reputation: 7749

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.

Upvotes: 0

ZZ Coder
ZZ Coder

Reputation: 75456

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>

Upvotes: 0

alphazero
alphazero

Reputation: 27224

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

Upvotes: 1

Related Questions