简体   繁体   English

Visual Studio Code 中的 java 代码无法识别 Clojure 项目中的命名空间

[英]Namespace in Clojure project cannot be recognized by java code in Visual Studio Code

I need some Java code to work with in Clojure project.我需要一些 Java 代码才能在 Clojure 项目中使用。 Following this page to learn how to mix Clojure/Java in Leiningen.按照此页面了解如何在 Leiningen 中混合使用 Clojure/Java。 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;但是,当我在 vscode 中打开项目时,Lexer.java 中的命名空间“myproject.records.time”; it cannot be recognized in vscode but it can be recognized in command line "lein do run, clean".它无法在 vscode 中识别,但可以在命令行“lein do run, clean”中识别。 I have already execute the command "java: clean language server workspace" in vscode, but the errors are still exist.我已经在vscode中执行了命令“java:clean language server workspace”,但是错误依然存在。 Please comment how to fix this error in vscode?请评论如何在 vscode 中修复此错误?

command line "lein do run, clean".命令行“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使用 vscode 在 Lexer.java 中无法识别命名空间“myproject.records.time”

在此处输入图像描述

You need to add Clojure.jar to current Project.您需要将Clojure.jar添加到当前项目。

Reference: leiningen - how to add dependencies for local jars?参考: leiningen - 如何为本地jars添加依赖?

Summarized procedures to solve the errors.总结了解决错误的程序。

  1. Download the latest stable release of Clojure.下载 Clojure 的最新稳定版本 Unzip it and find the file clojure-xyzjar.解压后找到文件clojure-xyzjar。 Copy this file into your project somewhere (eg. ./lib/clojure-1.10.3.jar ).将此文件复制到您的项目中的某个位置(例如./lib/clojure-1.10.3.jar )。 # thanks Molly Wang # 谢谢王莫莉

  2. Put the following statement into the project.clj .将以下语句放入project.clj中。

    :aot [myproject.records]

  3. Execute lein uberjar in the project directory, a jar file will be generated under the directory ./target/uberjar在项目目录执行lein uberjar ,在./target/uberjar目录下会生成一个./target/uberjar文件

    eg ./target/uberjar/XXX-0.1.0-SNAPSHOT.jar例如./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 );在 vscode 的左侧,有一个名为Referenced Libraries的选项卡,添加这两个文件clojure-1.10.3.jarXXX-0.1.0-SNAPSHOT.jar+ (在选项卡Referenced Libraries的右侧) ; respectively.分别。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM