Is there a way to compile multiple java source directories in a single maven project? Answer You can add a new source directory with build-helper:
Tag: java
Remove HTML tags from a String
Is there a good way to remove HTML from a Java string? A simple regex like will work, but some things like & won’t be converted correctly and non-HTML between the two angle brackets will be removed (i.e. the .*? in the regex will disappear). Answer Use a HTML parser instead of regex. This is dea…
During execution, how can a java program tell how much memory it is using?
During execution, how can a java program tell how much memory it is using? I don’t care how efficient it is! Answer VonC’s answer is an interactive solution – if you want to know programatically, you can use Runtime.totalMemory() to find out the total amount used by the JVM, and Runtime.free…
What is the best way to do GUIs in Clojure?
What is the best way to do GUIs in Clojure? Is there an example of some functional Swing or SWT wrapper? Or some integration with JavaFX declarative GUI description which could be easily wrapped to s-expressions using some macrology? Any tutorials? Answer I will humbly suggest Seesaw. Here’s a REPL-base…
Ways to save enums in database
What is the best way to save enums into a database? I know Java provides name() and valueOf() methods to convert enum values into a String and back. But are there any other (flexible) options to store these values? Is there a smart way to make enums into unique numbers (ordinal() is not safe to use)? Update T…
How to sanity check a date in Java
I find it curious that the most obvious way to create Date objects in Java has been deprecated and appears to have been “substituted” with a not so obvious to use lenient calendar. How do you check that a date, given as a combination of day, month, and year, is a valid date? For instance, 2008-02-…
How to split a string with any whitespace chars as delimiters
What regex pattern would need I to pass to java.lang.String.split() to split a String into an Array of substrings using all whitespace characters (‘ ‘, ‘t’, ‘n’, etc.) as delimiters? Answer Something in the lines of This groups all white spaces as a delimiter. So if I have …
Iterating through a Collection, avoiding ConcurrentModificationException when removing objects in a loop
We all know you can’t do the following because of ConcurrentModificationException: But this apparently works sometimes, but not always. Here’s some specific code: This, of course, results in: Even though multiple threads aren’t doing it. Anyway. What’s the best solution to this problem…
Build Eclipse Java Project from Command Line
Is there a way to compile an Eclipse-based Java project from the command line? I’m trying to automate my build (using FinalBuilder not ant), and I’m neither a Java nor Eclipse expert. I can probably figure out how to do this with straight java command line options, but then the Eclipse project fee…
What is the proper way to store app’s conf data in Java?
Where do you store user-specific and machine-specific runtime configuration data for J2SE application? (For example, C:UsersUSERNAMEAppDataRoaming</em> on Windows and /home/username on Unix) How do you get these locations in the filesystem in platform-independent way? Answer That depends on your kind of…