theme
theme

Reputation: 1117

create an executable jar with source code for debug

I know how to create a JAR file with the source code with maven, and also create an executable JAR. But my question is if there is any way of creating an executable JAR (so it contains all the .class files) that also contains the source code (so for each .class its corresponding .java file).

I want this for debugging with eclipse since my maven project is a library for another project and when debugging the bigger project I loose track when the execution reaches my library because the source code is missing in the JAR. I've found a solution among this forums that suggests to create two jars, one executable and another with .java files and set the source path in the IDE to point to the code JAR, but I would like to work with a unique JAR instead of two. Is that possible? if not with maven with another java tool? For instance merging both JAR files?

Lots of thanks.

Upvotes: 2

Views: 3209

Answers (2)

FrVaBe
FrVaBe

Reputation: 49341

You can declare your source directory as additinal resource directory

<build>
    <resources>
        <resource>
            <directory>${project.build.sourceDirectory}</directory>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
        </resource>
    </resources>
</build>

This will place the java files next to the class files - I do not know if your IDE supports debugging with this structure. Usually @Brian Agnew suggested way is the way to go.

Upvotes: 3

Brian Agnew
Brian Agnew

Reputation: 272297

I would have thought that if you're usign Maven you could create the binary as one deployable and the source jar as another. That way, your IDE should be able to transparently load the source corresponding to the binary jar you're using (in IDE it gives me a 'download' option).

See this link for more info.

The maven-source-plugin can be used to generate a source code jarW file for a project. Deploying this source jar to a remote repository can be useful for other developers so that they can 'attach source' and debug into the project source code.

Upvotes: 1

Related Questions