Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ant: How to compile jar that includes source attachment

Tags:

java

ant

How do I create a jar with Ant that includes the source attachment?

Maven does this, but I'm living maven-free since '03 (well, 2009, but it doesn't rhyme).

I can't see any options in the javac task which does this.

I tried including the source .java files in the fileset passed to the javac task, but this didn't work. When I try to view the source through something like Eclipse, I still get the 'no source attachment' display.

Any suggestions?

like image 483
Marty Pitt Avatar asked Aug 27 '10 14:08

Marty Pitt


1 Answers

You need two things to make it work in Eclipse:

  • Include the source files in the file set, so that each .java file exists in the same folder in the JAR as the corresponding .class file;
  • In the <javac> task, add the following parameter: debug="on". That way, you encode information into the .class files about the corresponding .java files that tools like Eclipse need in order to connect the two together.
like image 87
jqno Avatar answered Nov 15 '22 15:11

jqno