1

I have some Maven projects that I develop under Eclipse. When I want to see the source of a third party class, if the sources were published, I can simply read them:

enter image description here

However when I try to do the same with any of the default classes, those that are part of the JDK, I see a "Source not found" screen: enter image description here

One of my pom.xml contains this:

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-collections4</artifactId>
        <version>4.0</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

I was looking for a way to put the JDK in as a dependency, but I can't find a clue, how. I'm not even sure, if that would solve the problem, because my project compiles fine. I also am also aware that I can simply attach the sources through Eclipse, but again I'm not sure, if that would be a nice solution, as Maven can download the other sources.

Do you have any idea what could cause this, and how to solve the problem?

Bartis Áron
  • 618
  • 1
  • 10
  • 22
  • 3
    That is because you installed the JRE, not the JDK. The Java Runtime Library source code is only shipped with the JDK. Install the JDK and update Eclipse Workspace to use it, and the sources will be available. Remember, JDK stands for Java **Development Kit**, and source files are only needed during development. – Andreas Oct 24 '18 at 20:17
  • I already had both JDK and JRE installed in my Program Files directory. :-) For years... – Bartis Áron Oct 24 '18 at 20:19
  • 4
    Doesn't matter whether the JDK is installed *somewhere* on your hard disk, if you don't tell Eclipse where it is. As the "Class File Editor" screenshot shows, Eclipse has been told to use the `jre1.8.0_161` folder, not a `jdk1.8.0_161` folder. Probably because Eclipse itself is run by the JRE, not the JDK, so the workspace was created to use that same JRE by default. – Andreas Oct 24 '18 at 20:20
  • For how to fix, see e.g. [No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?](https://stackoverflow.com/q/19655184/5221149) – Andreas Oct 24 '18 at 20:30
  • Now this was helpful! Even if I didn't have a compile error. It's still strange that I have to handle the JDK classes differently than other 3PP classes. – Bartis Áron Oct 24 '18 at 20:35

0 Answers0