java - 如何修改 JAR 中包含的文件(该文件是 IntelliJ 中的依赖项)

标签 java scala intellij-idea jar

我正在 Intellij-Idea 中使用 Scala,但遇到了问题。我已经添加了 Java 标签,以便有 Java 经验的人也能回答我的问题。

在我正在使用的某个依赖项的 .ivy2/cache 文件夹中,有两个 jar 文件。一种包含 .class 文件,另一种包含 .scala 源文件。我希望能够修改其中一个 jar,将其放入我的 lib 文件夹中,然后使用包含我的更改的 jar 运行我的程序。

但是我有一个问题。我可以使用 jar uvf 修改源文件夹中的文件,但是当我将其放入 lib 并运行它时,更改不会显示。我已尝试注释掉 build.sbt 文件中的依赖项,但即使在运行 sbt update 后,它似乎仍在使用我的旧依赖项。

我的问题可以分为几个部分:

1) 我可以将仅包含 .scala 文件的 jar 文件放入 lib 文件夹中并期望它运行吗?

2)要删除依赖项,注释掉我的 build.sbt 文件中的行然后运行 ​​sbt update 就足够了吗?

3) 假设将 jar 文件作为依赖项运行的唯一方法是使用包含 .class 文件的 jar 文件。如果我没有任何其他项目文件(例如 build.sbt 文件),如何使用 .scala 文件用 .class 文件重建 jar?我有源文件,但我不确定如何使用它来重新创建 jar,而不需要通常打包在 Scala 项目中的所有其他信息。

我仅使用 Intellij 来编辑文件,并使用 sbt 来运行代码。

最佳答案

1) Can I just drop a jar file containing only .scala files in the lib folder and expect it to run?

这是不可能的,因为 jar 文件应该包含类文件,scala 文件将被视为资源而不是源文件。

2) To remove the dependency, is commenting out the line in my build.sbt file and then running sbt update enough?

我会运行sbt clean相反,我还没有尝试过sbt "show unmanagedBase"如果实际选择了该库,应该会列出该库。

3) Let us say that the only way to run the jar file as a dependency is to use a jar file containing .class files. How do I rebuild the jar with .class files using the .scala files if I don't have any of the other project files, like the build.sbt file? I have the source files, but I am not sure how to use it to recreate the jar without all the other information that usually comes packaged in a Scala project.

理想的方法是找到该源的完整存储库,更新源并运行 sbt publishLocal ,如果不可能,另一种方法是重建 build.sbt并继续添加库,直到库正确编译为止,希望它没有依赖项,或者只有一些依赖项。

关于java - 如何修改 JAR 中包含的文件(该文件是 IntelliJ 中的依赖项),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57334927/

相关文章:

java - Kafka 管道示例不会将所有记录从主题 a 传送到主题 b

java - 将 yaml 中的列表映射到 Scala 中的对象列表(Spring Boot)

java - 如何使用键盘快捷键在 Intellij-IDEA 中显示(展开)隐藏(折叠)的代码?

java - 属性动画的端监听器

java - 从 JPG 图像中读取文本数据

java - Selenium Grid 中不同 PC 上具有不同尺寸的屏幕截图

Scala:使用反射来发现你的内在对象(和欲望)?

scala - 如何将DataFrame中的struct映射到case类?

clojure - 什么指定了 Clojure REPL 的历史长度?

javascript - 如何设置 .eslintrc 识别 'require' ?