简体   繁体   中英

How to modify a file contained in a JAR that is a dependency in IntelliJ

I am working with Scala in Intellij-Idea, and have run into a problem. I have included the Java tag in case someone with Java experience can also answer my question.

In my .ivy2/cache folder for a certain dependency I am working with, there are two jar files. One contains .class files and one contains .scala source files. I want to be able to modify one of the jars, drop it in my lib folder, then run my program with the jar that includes my changes.

I have an issue though. I can modify the file in the source folder with jar uvf, but when I drop it in lib, and run it, the changes don't show up. I have tried commenting out the dependency in my build.sbt file, but it appears to still be using my old dependency even after I run sbt update.

My question can be divided into several parts:

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

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

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.

I use Intellij only to edit my files, and use sbt to run the code.

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

That's not possible because the jar file is expected to contain class files, scala files will be handled as resources instead of source files.

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

I would run sbt clean instead, I haven't tried but sbt "show unmanagedBase" is supposed to list you the library if it was actually picked.

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.

The ideal way would be to find the complete repository for that source, update the source and run sbt publishLocal , if that's not possible, another way would be to reconstruct the build.sbt and keep adding libraries until the library compiles properly, hopefully, it will have no dependencies, or a few only.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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