Can IDEA cope with src as the root folder in a sources.jar?

Am I right in assuming that in IntelliJ the root folder for a sources.jar cannot be "src" but must be the top level directory of the package?

I seem to recall that Eclipse can handle src as the root folder or but it looks to me as though IntelliJ is more strict?

6 comments
Comment actions Permalink

> but it looks to me as though IntelliJ is more strict?

What gives you that idea?
When attaching the sources simply select the "src" folder in the jar.

0
Comment actions Permalink

IDEA 8 can handle this. Previous versions of IDEA (to the best of my knowledge) could not. So your source would be something like:

\dev\lib\some-api-src.jar!\src\main\java

You can also use the file chooser to set this by expanding the sourcejar and drilling down into it.

0
Comment actions Permalink

Well I'm using 8.01 and it wouldn't work until I rejared my ehcache 1.2.3 sources jar.

that is. if I wanted to open a file say Ehcache ... it would always load the class file when "src" as the root
only when net became the root did it do as I expected.

This was with "Enter class name:"

0
Comment actions Permalink

steffi wrote:

Well I'm using 8.01 and it wouldn't work until I rejared my ehcache 1.2.3 sources jar.


that is. if I wanted to open a file say Ehcache ... it would always load the class file when "src" as the root
only when net became the root did it do as I expected.


This was with "Enter class name:"

That certainly is strange. My curiousity was peaked, so I downloaded the ehcache jars and defined a library as such:

classes:  /lib/ehcache/ehcache-1.2.3.jar
sources: /lib/ehcache/ehcache-1.2.3-sources.jar!/src

I was then able to navigate to the the source file via ctrl+N (i.e. the "Enter class name" dialog for the "Goto class" action). In fact, if I tried to set the sources to the 'net' directory, I received an "Invalid" warning from IDEA. So I'm not sure what might be happening for you. Let us know if you figure out what was causing the strange behavior.

0
Comment actions Permalink

This may or may not be relevant but I obtained my sources using maven.

Are you sure the root of your sources jar was src and not net?

When you show !src is this what IDEA derived from the jar when it sees it?

0
Comment actions Permalink

When I did the above test, I manually downloaded the jars from http://ibiblio.org/maven/ and then manually configured a library definition. So I directly specified the ...jar!src directory.

I did just add the dependency definition to a maven project and had IDEA/maven download the artifacts, and auto-configure the library. In that case IDEA auto defined the sources as simple being the jar file, and not the src directory within the jar file. So I had to go into the library definition and detach the auto defined sources (to the sources jar file) and manually attach the sources with the path ~/.m2/repository/net/sf/ehcache/1.2.3/ehcache-1.2.3.jar!/src

It might be a cool new feature for IDEA to automatically determine the directory or directories within a jar that have the source files when creating the library definition (like it does for new projects). But doesn't the maven specification for source JARs indicate that the packages are in the JAR's root? In other words, isn't the ehcahe 1.2.3 jar in violation of the standard way sources are packaged?

0

Please sign in to leave a comment.