Java "constant string too long" compile error. Only happens using Ant, not when using Eclipse

Someone is trying to send you a message :-) In the time you've spend fiddling with compiler versions you could have loaded the data from a text file - which is probably where it belongs.

Check out:

  • java.util.Properties
  • Apache Commons FileUtils.readFileToString()

I found I could use the apache commons lang StringUtils.join( Object[] ) method to solve this.

public static final String CONSTANT = org.apache.commons.lang.StringUtils.join( new String[] {
  "This string is long", 
  "really long...", 
  "really, really LONG!!!" 
} );

Nothing of above worked for me. I have created one text file with name test.txt and read this text file using below code

String content = new String(Files.readAllBytes(Paths.get("test.txt")));

Tags:

Java

Eclipse

Ant