我想将 clojure 库导入到基于 Maven 的 java 11 应用程序中。使用的clojure版本大多是1.8+,使用boot构建。我可以在语言版本上保持灵 active ,但对 clojure 使用 boot 是一个要求。
我已经对此进行了一些阅读,但我无法找到任何最近的解决方案,并且没有使用 boot.鉴于它们都是 JVM 语言,我希望这不会太复杂,但不确定从哪里开始。
最佳答案
普通的旧 Maven 应该足以检索任何 Clojure 依赖项,因为它支持添加不同的包源。您只需添加另一个托管 Clojure 包的存储库:
<repositories>
<repository> <!-- You probably have this already -->
<id>central</id>
<url>https://repo1.maven.org/maven2/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
<repository><!-- You'll need to add this -->
<id>clojars</id>
<url>https://repo.clojars.org/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
要在 Maven 中添加更多依赖项,您可以在 Clojars 中搜索 Clojure 包或在 Maven Repository 。例如,以下是 clj-time 库的 Maven 存储库中的条目: https://mvnrepository.com/artifact/clj-time/clj-time/0.15.1
在 Maven 中添加该依赖项的相关部分是:
<dependency>
<groupId>clj-time</groupId>
<artifactId>clj-time</artifactId>
<version>0.15.1</version>
</dependency>
将库作为依赖项提供后,您可以按照本指南中的说明从 Java 调用它:https://clojure.org/reference/java_interop#_calling_clojure_from_java
如果您需要编写大量代码来使用您感兴趣的库,那么最好编写一个 Clojure 函数作为入口点,而不是尝试编写大量调用 Clojure 库代码的 Java 代码。
关于java - 如何使用 Spring-Boot 在 Java 项目中使用 Clojure 库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56885586/