Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print the sourcecode of a whole java project

I have to print the whole sourcecode of a java-project. The final version should look like: Eclipse: File -> Print. But with this function you can only print one file at once.

Is there a way to print (or create a pdf/rtf of) the whole project (all *.java, *.xml, ... files) with one command?

Im using eclipse galileo on windows xp sp3


EDIT: For each class/file the page should (more or less) look like this:

C:\..\..\..\LibraryExtractor.java

1 package utils.libraries; 2 3 import java.io.File; 9 10 /** 11 * @ 12 * @ 13 * @ 14 */ 15 public class LibraryExtractor { 16 17 /** 18 *  19 *  20 * 21 *  22 *  23 * 24 * 25 */ 26 public static void extranctLibrary(String library, File targetFile) throws IOException, URISyntaxException { 27 targetFile.getParentFile().mkdirs(); 28 if (!targetFile.exists()) 29 targetFile.createNewFile(); 30 31 ClassLoader classLoader = LibraryExtractor.class.getClassLoader(); 32 InputStream in = classLoader.getResourceAsStream(library); 33 OutputStream out = new FileOutputStream(targetFile); 34 35 byte[] buf = new byte[1024]; 36 int len; 37 38 while ((len = in.read(buf)) > 0) 39 out.write(buf, 0, len); 40 41 in.close(); 42 out.close(); 43 } 44 } 45 

SOLUTION:

  1. enscript (with Cygwin)

  2. Java2Html Eclipse-Plugin (only works with Europa)

like image 854
oliver31 Avatar asked Dec 17 '09 11:12

oliver31


People also ask

How can I see the source code of a Java application?

The IDE's built-in Source Editor enables you to view, create, and edit your Java source code. Open the Source Editor window by double-clicking a node in the Projects window, Files window, or Navigator window. Alternatively, you can open the Source Editor by choosing File > New to create a new file.

How can I get source code in eclipse?

Go to Windows->Preferences->Java->Installed JREs. Select Browse and navigate to the C:\Program Files\Java\jdk1. 6.0_21 directory. Eclipse will automatically find the source and associate it with the JDK classes.

How do I print from eclipse?

println() line in eclipse without typing the whole line type sysout and press Ctrl + space.

How can I view the source code of a class file in eclipse?

Go to the Package Explorer view with the file open in the current editor. Click the "Link with Editor" toggle (the two arrows). This should jump you to the class file you are viewing, which should be in the jar you are using. If the jar is in a library, you should see the path to the jar in the package explorer.


1 Answers

If you don't mind installing Cygwin, or running on Linux, the following command will do what you want:

enscript -r -2 --file-align=2 --highlight --line-numbers -o - `find . -name '*.java'` | ps2pdf - files.pdf 

enscript is a program for converting text files to a variety of output formats; PostScript is the default, but you can also produce HTML, RTF, and a few others. The -r option says to print in landscape, -2 is two columns per page (save trees), --file-align=2 says that each new file should start on its own physical page, --highlight turns on language-specific syntax highlighting (it will try to figure out the language, or you can specify "java"), --line-numbers should be obvious, and -o - sends the output to standard-out (where it's piped to ps2pdf).

find generates the list of files; here I'm telling it to find all Java files under in the current directory. The output is passed as arguments to enscript; for "50-100 files" you should be OK, but you might need to read about xargs. You could get rid of the -name argument to generate a list of all files, or add multiple -name arguments to add more file types to the list; I wouldn't go with the "all files" approach, because then you'll get source-control files.

ps2pdf takes the PostScript output from enscript and converts it to PDF, which you can print.

like image 70
kdgregory Avatar answered Sep 22 '22 09:09

kdgregory