Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make netbeans attach maven sources to artifacts

I'm having some issues with a third party library that I'd like to step into. Netbeans provides a "Download Sources" option when the libraries node is right clicked. This downloads the sources from svn correctly, a source icon is attached to the dependency node, all is peachy. However, when I open one of the classes it gives me a generated skeleton just as it would if there was no source attached. Further more when there is a maven source present it seems there is no option to attach a local source manually so I can't work round this.

What are everyone else's experiences of this feature?

FYI the library in question is smack 3.1.0 http://www.igniterealtime.org/projects/smack/index.jsp

like image 701
Ollie Edwards Avatar asked Aug 18 '10 15:08

Ollie Edwards


2 Answers

As Pascal writes, the resolution of source artifacts happens via convention, so if the dependency is at:

<dependency>
    <groupId>com.yourcompany</groupId>
    <artifactId>yourartifact</artifactId>
    <version>1.2.3</version>
</dependency>

it will look for the source artifact at:

<dependency>
    <groupId>com.yourcompany</groupId>
    <artifactId>yourartifact</artifactId>
    <version>1.2.3</version>
    <classifier>sources</classifier>
</dependency>

So what you can do is download the source from the source download page, create a jar from it and run install:install-file as seen on the usage page:

mvn install:install-file -Dfile=your-created-source.jar \
                         -DgroupId=jivesoftware \
                         -DartifactId=smack \
                         -Dversion=3.1.0 \
                         -Dclassifier=sources \
                         -Dpackaging=jar \
                         -DgeneratePom=false

That way the convention will work and netbeans will find your sources automatically.

EDIT: added packaging

like image 139
Sean Patrick Floyd Avatar answered Oct 09 '22 08:10

Sean Patrick Floyd


Netbeans provides a "Download Sources" option when the libraries node is right clicked. This downloads the sources from svn correctly, a source icon is attached to the dependency node, all is peachy.

If we're talking about Maven here, I don't think that this is what is happening. The Download Sources feature tells Maven to download a sources artifact (e.g. foo-1.0-SNAPSHOT-sources.jar) for a given dependency from a Maven repository. And obviously, this only works if a given dependency is providing a -sources jar. But that's not the case of smack-3.1.0.

like image 29
Pascal Thivent Avatar answered Oct 09 '22 06:10

Pascal Thivent