26

I was recently trying to import a library to use for something I am working on.

https://sites.google.com/site/piotrwendykier/software/jtransforms

I was having some difficulty because the JAR that I added to the build path was the "JTransforms-3.0-sources.jar" and not the "JTransforms-3.0.jar".

Now I am sort of scratching my head and just wondering what that first sources.jar was if it didn't have any of the classes that I wanted to use in it.

What is it and what is it for?

2 Answers 2

39

That sources jar is a jar that contains only the source code (the .java files) corresponding to the compiled artifact. It is useful to add it as a source attachment in your IDE, to publish the sources, etc.

As it only contains sources, not compiled classes (.class files), it is of no use as a library dependency.

0
18

What is it: Source JARs are the JAR file which contains only source code files i.e. .java files, and no compiled .class files. For example, you can download OpenJDK™ Source files from http://download.java.net/openjdk/jdk8/

What is it for: It is useful for other developers so that they can 'attach source' and debug into their project source code.

2
  • is there any app which ports from class JAR to source jar ??
    – LOG_TAG
    Mar 29, 2019 at 10:15
  • 1
    @LOG_TAG There are several, they are called "java decompilers" and what they do it try to interpret .class bytecode into their original source form. However there are different limitations on doing this, so more often than not the source will not be as readable as you would expect, but could be useful anyways. Mar 8, 2020 at 5:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.