0

I need some Java code to work with in Clojure project. Following this page to learn how to mix Clojure/Java in Leiningen. The project was running smoothly, the result is same as expected. However, when I open the project in vscode, the namespace "myproject.records.time" in Lexer.java; it cannot be recognized in vscode but it can be recognized in command line "lein do run, clean". I have already execute the command "java: clean language server workspace" in vscode, but the errors are still exist. Please comment how to fix this error in vscode?

command line "lein do run, clean". Working successfully

=> #'myproject.main/-main
({:type :error, :value "4"}
 {:type :error, :value "3"}
 {:type :error, :value "2"}
 {:type :error, :value "1"}
 {:type :error, :value "0"})
=> nil

the namespace "myproject.records.time" cannot be recognized in Lexer.java with vscode

enter image description here

Steffan Westcott
  • 2,121
  • 1
  • 3
  • 13
madeinQuant
  • 1,721
  • 1
  • 18
  • 29

2 Answers2

1

You need to add Clojure.jar to current Project.

Reference: leiningen - how to add dependencies for local jars?

Molly Wang-MSFT
  • 7,943
  • 2
  • 9
  • 22
  • Thanks for your comment. This is a Clojure project in Leiningen. Can we use gradle with Leiningen? – madeinQuant May 18 '21 at 13:27
  • Sorry for my misunderstanding, I've edit my answer, please have a try. – Molly Wang-MSFT May 19 '21 at 02:00
  • Thanks for your help. your suggestion which solved a part of errors. However, errors of user defined library cannot be solved. Hopefully, I can find a solution to solve the errors this page. Reading this page "https://push-language.hampshire.edu/t/calling-clojure-code-from-java/865". – madeinQuant May 19 '21 at 03:20
  • Glad to know your question had been solved. Happy Coding. :) – Molly Wang-MSFT May 19 '21 at 03:33
0

Summarized procedures to solve the errors.

  1. Download the latest stable release of Clojure. Unzip it and find the file clojure-x.y.z.jar. Copy this file into your project somewhere (eg. ./lib/clojure-1.10.3.jar). # thanks Molly Wang

  2. Put the following statement into the project.clj.

    :aot [myproject.records]

  3. Execute lein uberjar in the project directory, a jar file will be generated under the directory ./target/uberjar

    e.g. ./target/uberjar/XXX-0.1.0-SNAPSHOT.jar

  4. In left hand side of vscode, there is a tab named Referenced Libraries, add these two files clojure-1.10.3.jar and XXX-0.1.0-SNAPSHOT.jar with +(at the right hand side of the tab Referenced Libraries); respectively.

enter image description here

madeinQuant
  • 1,721
  • 1
  • 18
  • 29