eclipse 如何将补丁应用于 Java 项目?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/986222/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to apply a patch to a Java project?
提问by omg
The patch is for nutch 0.9: http://cvs.tty.org/~butch/blog/nutch_0.9_OR.patch
该补丁适用于 nutch 0.9:http://cvs.tty.org/~butch/blog/nutch_0.9_OR.patch
How should I apply the patch correctly?
我应该如何正确应用补丁?
OS is windows XP
操作系统是 Windows XP
More specifically, I'm using eclipse to debug a nutch project.
更具体地说,我正在使用 eclipse 来调试一个 nutch 项目。
Here is my trial:
这是我的试验:
D:\nutch-0.9.bak>patch -p0 < nutch_0.9_OR.patch
Hmm... Looks like an ed script to me...
(Patch is indented 5 spaces.)
The text leading up to this was:
--------------------------
|diff -rBNu src.orig/java/org/apache/nutch/analysis/NutchAnalysisConstants.java src/java/org/apache/nutch/analysis/NutchAnalysisConstants.java
|--- src.orig/java/org/apache/nutch/analysis/NutchAnalysisConstants.java 2009-03-10 11:34:01.000000000 -0700
|+++ src/java/org/apache/nutch/analysis/NutchAnalysisConstants.java 2009-03-10 14:11:55.000000000 -0700
|@@ -4,30 +4,34 @@
| public interface NutchAnalysisConstants {
|
| int EOF = 0;
|- int WORD = 1;
|- int ACRONYM = 2;
|- int SIGRAM = 3;
|- int IRREGULAR_WORD = 4;
|- int C_PLUS_PLUS = 5;
|- int C_SHARP = 6;
|- int PLUS = 7;
|- int MINUS = 8;
|- int QUOTE = 9;
|- int COLON = 10;
|- int SLASH = 11;
|- int DOT = 12;
|- int ATSIGN = 13;
|- int APOSTROPHE = 14;
|- int WHITE = 15;
|- int WORD_PUNCT = 16;
|- int LETTER = 17;
|- int CJK = 18;
|- int DIGIT = 19;
|+ int QOR = 1;
|+ int WORD = 2;
|+ int ACRONYM = 3;
|+ int SIGRAM = 4;
|+ int IRREGULAR_WORD = 5;
|+ int C_PLUS_PLUS = 6;
|+ int C_SHARP = 7;
|+ int PLUS = 8;
|+ int MINUS = 9;
|+ int QUOTE = 10;
|+ int COLON = 11;
|+ int SLASH = 12;
|+ int LPAREN = 13;
|+ int RPAREN = 14;
|+ int DOT = 15;
|+ int ATSIGN = 16;
|+ int APOSTROPHE = 17;
|+ int WHITE = 18;
|+ int WORD_PUNCT = 19;
|+ int LETTER = 20;
|+ int CJK = 21;
|+ int DIGIT = 22;
|
| int DEFAULT = 0;
|
| String[] tokenImage = {
| "<EOF>",
|+ "\"OR\"",
| "<WORD>",
| "<ACRONYM>",
| "<SIGRAM>",
|@@ -39,6 +43,8 @@
| "\"\\"\"",
| "\":\"",
| "\"/\"",
|+ "\"(\"",
|+ "\")\"",
| "\".\"",
| "\"@\"",
| "\"\\'\"",
|diff -rBNu src.orig/java/org/apache/nutch/analysis/NutchAnalysis.java src/java/org/apache/nutch/analysis/NutchAnalysis.java
|--- src.orig/java/org/apache/nutch/analysis/NutchAnalysis.java 2009-03-10 11:34:01.000000000 -0700
|+++ src/java/org/apache/nutch/analysis/NutchAnalysis.java 2009-03-10 14:11:55.000000000 -0700
|@@ -56,7 +56,11 @@
| queryString, (analyzer != null) ? analyzer : new NutchDocumentAnalyzer(conf));
| parser.queryString = queryString;
| parser.queryFilters = new QueryFilters(conf);
|- return parser.parse(conf);
|+ try {
|+ return parser.parse(conf);
|+ } catch (ParseException pe) {
|+ throw new IOException("Parse exception: " + pe);
|+ }
| }
|
| /** For debugging. */
|@@ -77,44 +81,60 @@
| String field;
| boolean stop;
| boolean prohibited;
|+ boolean required;
| nonOpOrTerm();
| label_1:
--------------------------
File to patch:
回答by Robert Munteanu
Since you mentioned Eclipse - right-click on the project, go to Team -> Apply patch.
既然你提到了 Eclipse - 右键单击项目,转到 Team -> Apply patch。
回答by Zoltán Ujhelyi
You should use right click on project, Team/Apply patch.
您应该使用右键单击项目,团队/应用补丁。
The third step of the wizard (review patch) contains a Patch Content section where the modified source files are listed.
向导的第三步(检查补丁)包含一个补丁内容部分,其中列出了修改后的源文件。
回答by Zoltán Ujhelyi
I'm assuming the following:
我假设如下:
- UnxUtils installed in C:\unxutils
- "C:\unxutils\bin" and "C:\unxutils\usr\local\wbin" included in your PATH variable.
- Nutch files in C:\nutch-0.9
- nutch_0.9_OR.patchconverted to windows line delimiters else you will get an error like this one "Assertion failed: hunk, file patch.c, line 321"
- nutch_0.9_OR.patchcopied to C:\nutch-0.9
- UnxUtils 安装在C:\unxutils
- PATH 变量中包含“C:\unxutils\bin”和“ C:\unxutils\usr\local\wbin”。
- C:\nutch-0.9 中的Nutch 文件
- nutch_0.9_OR.patch转换为 windows 行分隔符,否则你会得到这样的错误“断言失败:大块头,文件 patch.c,第 321 行”
- nutch_0.9_OR.patch复制到 C:\nutch-0.9
Then open a command line cd C:\nutch-0.9 patch.exe -p0 -u -i nutch_0.9_OR.patch
然后打开命令行 cd C:\nutch-0.9 patch.exe -p0 -u -i nutch_0.9_OR.patch
Finished!
完成的!
回答by PhiLho
- You need the original source (at the given version!)
- You need the patchUnix utility (I have a copy for Windows coming with my precious UnxUtils, google that name to find the SourceForge project). Oh, well, just did it to ensure name is right: UnxUtils
- You apply the patch, it will change the sources
- You compile the project.
- 您需要原始来源(在给定版本中!)
- 您需要修补Unix 实用程序(我有一份 Windows 的副本以及我珍贵的 UnxUtils,谷歌这个名字可以找到 SourceForge 项目)。哦,好吧,这样做是为了确保名称正确:UnxUtils
- 你应用补丁,它会改变来源
- 你编译项目。
回答by Brian Agnew
回答by RichieHindle
One: Make a backup of your code.
一:备份你的代码。
Two: You did make a backup of your code, didn't you? 8-)
二:你确实备份了你的代码,不是吗?8-)
Three:
三:
cd \path\to\nutch
patch -p0 < nutch_0.9_OR.patch