问题描述
我必须打印一个java项目的整个源代码。最终版本应如下所示: Eclipse:File - > Print 。
但是使用此功能,您只能一次打印一个文件。
有没有办法打印整个项目(或创建pdf / rtf) (所有* .java,* .xml,...文件)与一个命令?
我使用eclipse galileo在windows xp sp3
编辑:对于每个类/文件,页面应该(或多或少)看起来像这样:
C:\..\..\..\LibraryExtractor.java
1包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
解决方案:
-
(与Cygwin)
-
Eclipse -Plugin(只有
适用于欧罗巴)
您不介意安装,或在Linux上运行,以下命令将执行您想要的:
enscript -r -2 --file-align = 2 --highlight --line-numbers -o - `find。 -name'* .java'` | ps2pdf - files.pdf
enscript 是一个将文本文件转换为各种输出格式; PostScript是默认的,但您也可以生成HTML,RTF等。 -r
选项表示以横向打印, -2
是每页两列(保存树), - file-align = 2
表示每个新文件应该在自己的物理页面上开始, - 突出显示
打开语言特定的语法高亮(它会尝试找出语言,或者你可以指定java), - 行号
应该是明显的,而 -o -
将输出发送到标准输出(在管道中输入到 ps2pdf )。
em> find 生成文件列表;这里我告诉它找到当前目录下的所有Java文件。输出作为参数传递给 enscript ;对于50-100文件,您应该可以,但是您可能需要阅读关于 xargs 的信息。您可以摆脱 -name
参数来生成所有文件的列表,或者添加多个 -name
参数添加更多文件类型到列表中;我不会用所有文件的方法,因为那将得到源代码控制文件。
ps2pdf 采用PostScript输出从 enscript ,并将其转换为PDF,您可以打印。
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:
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.
这篇关于打印整个java项目的源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!