IntelliJ: Hide .class files in file search in Maven Java project - java

I am working on a Maven Java project using the latest version of IntelliJ CE. I want to be able to view the source code of my Maven dependencies using the IDE's file search tool (ie, ⌘⇧O). However, I am getting both the .java and the .class files for each of the Java class names of a given dependency. Ideally, I only get results for the .java files (source code) instead of the .class files (bytecode). The .class files come from the dependency's JAR file, while the .java file comes from the dependency's sources-JAR file.
Is there any existing way to accomplish this? Thank you.

As answered by Bastien Jansen in the comments, the answer was to use Navigate Class (⌘O) instead of Navigate File (⌘⇧O).

Related

Difference between ClassPath and SourcePath in Project SDKs under Platform Settings in Intellij IDEA?

I'm using Intellij IDEA 2019.3 and when I add a new Java library (.jar files) to my project, in order to access library implementation (.java file instead of .class file), I have to add all necessary .jar file into ClassPath tab and .zip file into Sourcepath. It's working and I don't know exactly why it does. Is there any explanation?
Another question: What's Platform Settings? Why does it have such a name?
Platform settings is responsible for so called "global" settings in your intellij IDEA. Adding java libraries under class/source path let all yours projects access to these libraries.
As for difference between classpath and sourcepath.. You actually answer your question. In order to access class files (.class) you need jar file to be added to classpath. In order to access actual implementation (.java), say for debugging purpose, you have to add it to sourcepath.
See more Define an SDK in Intellij IDEA
It's better to add .jar to project settings not to platform. You could add specific libraries in Project structure -> Libraries tab
See Libraries and Global Libraries
Then if you want to navigate to .java file you could open corresponding .class file and add source file using one of options in upper right corner:
After that you will see Classes file and Sources file in Libraries tab:

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.

maven does not include fxml file

I try to create a maven project of a java program, which includes two java classes and a fxml file, which are all located in the same directory (src/main/java/package).
When i install the project with maven it does not copy the fxml file into the .jar file so that the program does not work any more. A few hours ago I basically created an equivalent project and everything worked fine.
How can I fix that?
The Maven convention is that Java files go in src/main/java. Any non-Java files go in src/main/resources.
The Eclipse emulation of Maven does not make this distinction. Both directories are source folders which is incorrect but "good enough" to handle correct Maven projects.
So, move your file to the correct location.

Search files by text in Maven Dependencies folder in Eclipse

I have a Java Maven project in Eclipse so all the Maven artifact jar files are listed in the "Maven Dependencies" package (folder?) in the Project Explorer. I would like to do a simple text search inside the *.class files inside the jars the same way I do a file containing text search. I can't use *.class directly in File name patterns field in Eclipse File search and if I use *.jar that will return binary results.
Was actually a bit surprised not to find answer to this so maybe I am missing something?
If you want to search for some text in some jar file, you need to select Java Search Tab. Press CTRL+H to see the screen bellow.
Note that I'm searching in Application libraries as well.
In the image bellow you can see the result of my search.
And finally, the reference in code inside of jar file.
I hope it helps you.

Empty .jar File in Ecilipse

i just imported a Jackson's annotation library and imported it into my java application project in eclipse. However, after importing, the package doesn't contain any java files.
If I open the .jar file using a .zip extractor, all the java files are present.
Anyone knows how to rectify this?
Thanks already.
Screenshot : Empty
You need to add the binary jars (jar which has the class files), and not the source jar files.
If you add the source jar files and imported to your buildpath eclipse wont show any java files.
Instead first add the jar containing the class files, and then you can attach the source jar to the binary.

Categories