3

To assist in our ability to step through code when debugging I'd like to recommend our JAR files be built to include source code. I'm wondering what issues that might cause. My immediate thought was that the JAR files would be slightly larger. I can live with that. Are there other issues I need to consider?

TIA

Todd
  • 2,829
  • 5
  • 34
  • 56
  • Well there is the whole code security thing, but with decompilers this is almost a nil point. – thatidiotguy Oct 10 '12 at 14:27
  • In some cases the size of the jar files matter. Eg. the deployment on a server is faster without .java files. – sics Oct 10 '12 at 14:29

4 Answers4

4

Normally you separate compiled code and source code into two different jars.

Then you can attach the source-code jar in your IDE when you need to debug the code.

A build tool like maven will easily do that for you.

maba
  • 47,113
  • 10
  • 108
  • 118
2

I highly recommend it. I do this and so do some open source projects (e.g. jMock, Hamcrest, GWT).

It saves fussing about with separate source jars. It also means that if at some point in the future the source project is lost (as sometimes happens in large organizations) the maintenance programmers down the line will have a fighting chance of recreating it.

If you're happy that those people with access to the jar can see your source code and are prepared to pay the penalty of an increase in jar size (and a probably negligible increase in the time to create, transfer and deploy the jar) then that's all you need to worry about. There aren't any other issues as far as I am aware.

Just because the Maven standard is to keep source files separate doesn't mean you have to do it that way.

ᴇʟᴇvᴀтᴇ
  • 12,285
  • 4
  • 43
  • 66
1

I would normally create a separate source .jar. Maven can easily create this, and IDEs know how to access/download these.

Community
  • 1
  • 1
Brian Agnew
  • 268,207
  • 37
  • 334
  • 440
0

Some tools in the java space will take the source files from the classpath (i.e. from within the jar) and do nasty things.

Typically where you see this is if you add a dependency on a jar that does this... then you end up with those source files being compiled again into the dependent project and bundled in its jar and then all classloader hell breaks loose as classes get loaded from one source and another.

Just don't do it. Follow the Maven way (even if not using Maven) and create a separate -sources.jar

Stephen Connolly
  • 13,872
  • 6
  • 41
  • 63
  • Which tools do this? It sounds like FUD to me. – ᴇʟᴇvᴀтᴇ Oct 10 '12 at 14:38
  • There are some specific artifacts in the Central repository that have this issue. And about once a year somebody depends on the wrong version and then when they try to compile their project they get a pile of errors. I am trying to find on google but "bad jar including sources" has no answers on the first couple of pages, so will need to trawl the M-L archives. Not FUD, a real problem. – Stephen Connolly Oct 10 '12 at 15:50