5

Actually I want to automate the process of removing all the System.out.println() statements from the entire project before delivering the project to the client. How to do it?

user3728785
  • 59
  • 1
  • 4
  • 1
    Which `IDE` you are using ? – Nidheesh Jun 11 '14 at 10:09
  • I dont want to replace them with any statement, i just want to delete all the occurences of System.out.println() statement of the project automatically. – user3728785 Jun 11 '14 at 10:10
  • 1
    What about [this](http://stackoverflow.com/questions/14044205/system-out-println-removal-comment-from-multiple-java-source-files) – Nidheesh Jun 11 '14 at 10:11
  • 1
    Do you really want to *delete* them? Or do you just want to disable "debugging" output to stdout? And do you want to do this once and for all or just leave it there and do it just before release? – proskor Jun 11 '14 at 10:11
  • 7
    Not that you asked for a more convenient way, but had you used a logging framework in the first place, you could just have disabled the code. Just an idea for upcoming projects. – Janis F Jun 11 '14 at 10:12
  • 1
    if you will be further developing the application after handing a first release to the client (and usually otherwise too), using `System.out.println()` is a bad idea anyways. Use a configurable logging framework, e.g. logback, saves you from that work. C and the likes have a preprocessor which can strip out debugging code altogether. – Silly Freak Jun 11 '14 at 10:13
  • You should consider using log frameworks – Abimaran Kugathasan Jun 11 '14 at 10:14
  • This question has already been asked before – tucuxi Jun 11 '14 at 10:15
  • Yes i really want to delete them all automatically. @proskor – user3728785 Jun 11 '14 at 10:35
  • 1
    Log4j and other customized Logging frameworks are there in place, but still developers have used Sop's. Cant help. Now i have got to remove all the Sop's from the entire project. – user3728785 Jun 11 '14 at 10:38

7 Answers7

2

Press ctrl+H go to File search. Fill containing text as System.out.println(*); , File name pattern as *.* and click on Replace Button.

After the search it prompt for a replacing text, Press OK.

rinuthomaz
  • 1,393
  • 2
  • 23
  • 38
0

You can use the Replace functionality of any decent text editor like Notepad++. Just replace the regular expression System.out.println(\*) with an empty string

Oscar
  • 13,594
  • 8
  • 47
  • 75
  • 2
    And what will happen to `System.out.println(SOME_STRING);`? (Hint: Some regex is probably needed) – amit Jun 11 '14 at 10:08
  • @amit With Notepad++ you can use regular expressions to do a replacement. System.out.println(\*); – Oscar Jun 11 '14 at 10:10
  • Well, it should have been said. Also what happens for `System.\nout.\nprintln(SOME_STRING);` (But the editted answer is getting better) – amit Jun 11 '14 at 10:11
  • 2
    Oscar, is that a valid regex? I don't know their flavor in Notepad++, but no javascript/Java/Perl regex looks like that... – tucuxi Jun 11 '14 at 10:12
  • @tucuxi No, it isn't, I just wrote it as a sample. – Oscar Jun 11 '14 at 10:14
  • This is not so simple. Some time SOME_STRING will extends to multiple lines. Ex System.Out...("fdf" +"fddfdfdfd" + .... – Chandrayya G K Jun 11 '14 at 10:29
  • @ChandrayyaGK Regex can handle matches in multiples lines too, so same solution still is valid. – Oscar Jun 11 '14 at 10:54
0

use the "find all" function of your IDE and delete it manually

with Eclipse:

CTRL+H

then "File search"

type "System.out.println(*);" and click "Replace..."

jhamon
  • 3,603
  • 4
  • 26
  • 37
0

Click CTRL+F and choose Replace. Then, replace System.out.println with //System.out.println

user3722371
  • 145
  • 6
  • And what will happen to `System.out.println(SOME_STRING);`? (Hint: Some regex is needed) – amit Jun 11 '14 at 10:09
  • 1
    If you write System.out.println, without the brackets, that will take care of everything. (I edited my answer) – user3722371 Jun 11 '14 at 10:10
  • 2
    But then the code won't compile, you will have to manually delete the `(STRING)` from everywhere. – amit Jun 11 '14 at 10:11
  • Well then, probably System.out.println(*), I haven't used regular expressions for finding and replacing, but it might work. – user3722371 Jun 11 '14 at 10:12
  • 1
    Replace system.out.print with //system.out.print (would be a problem with multiline) or just replace it with something like log4j – Mister Henson Jun 11 '14 at 10:15
  • Or, an even easier fix that will work for sure, is to replace it with //System.out.println – user3722371 Jun 11 '14 at 10:15
  • @user3722371 No, it won't. A long diagnostic message might be split across lines of source code, leaving you with invalid trailing lines. – nanofarad Jun 11 '14 at 10:37
0

You can do it by find in Project option then give System.out.println( to your search criteria then remove them all. and match criteria will not be match whole word.

If INtellij Idea then Edit -> Find ->Find in Path.

If NetBeans then Edit -> Find In Projects

user3145373 ツ
  • 7,858
  • 6
  • 43
  • 62
0

If You are want to automate this kind of stuff, you can use Ant and preprocess your source code files with ReplaceRegExp task. We use this to compile the product version into the binaries.

This is taken (and modified slightly) from the online doc:

<replaceregexp match="System.out.println(.*);" replace="" flags="g" byline="true">
  <fileset dir="${src.dir}" includes="**/*.java"/>
</replaceregexp>
proskor
  • 1,382
  • 9
  • 21
0

There is a plugin which does exactly what you want. This will Comment / Remove out all System.Out's. Check this link also. Its is said here that it is a solution for System.out.println removal/comment from multiple java source files post.

Community
  • 1
  • 1
Chandrayya G K
  • 8,719
  • 5
  • 40
  • 68