What is the best way to create Velocity Template from a String? I’m aware of Velocity.evaluate method where I can pass String or StringReader, but I’m curios is there a better way to do it (e.g. any advantage of creating an instance of Template). Answer There is some overhead parsing template. You…
tomcat session replication – not serialized exception
I am currently working on one messy web application. In this application, there is a class that holds all the data sources. And whenever the need to connect to a specific data source, the method in the instance of the class is called with a parameter to select the data source.And class is like follows And on …
Java http call returning response code: 501
I am having an issue with this error: See this code: Answer A 501 response means “not implemented”, and is usually taken to mean that the server didn’t understand the HTTP method that you used (e.g. get, post, etc). I don’t recognise ClientHttpRequest , but you have a line that says an…
Simulate touch command with Java
I want to change modification timestamp of a binary file. What is the best way for doing this? Would opening and closing the file be a good option? (I require a solution where the modification of the timestamp will be changed on every platform and JVM). Answer The File class has a setLastModified method. That…
What are all the possible values for SQLException.getSQLState?
SQLException.getSQLState retrieves the SQLState for the SQLException object. What are all the possible values that can be returned by this method? Can I use the value to identify specific errors that occurred in the database (i.e. can this value tell me if it was a PK violation, or a unique constraint, or col…
How do I get my Maven Integration tests to run
I have a maven2 multi-module project and in each of my child modules I have JUnit tests that are named Test.java and Integration.java for unit tests and integration tests respectively. When I execute: mvn test all of the JUnit tests *Test.java within the child modules are executed. When I execute mvn test -Dt…
Copy directory from a jar file
I have recently developed an application and created the jar file. One of my classes creates an output directory, populating it with files from its resource. My code is something like this: Unfortunately this doesn’t work. I tried the following without luck: Using Streams to solve similar stuff on other…
Is there an implementation of JSR-303 (bean validation) available?
I know there are non-standard frameworks such as commons-validator, and hibernate validator. I wanted to know if someone knows an implementation of the official standard. Answer Hibernate Validator is the reference implementation of JSR-303
Using the NetBeans GUI editor, how can I create a JTextField or JFormattedText field that must be validated against a regular expression?
I have a regular expression (d{4}w{3}(0[1-9]|[12][0-9]|3[01])([01][0-9]|2[0-3])([0-5][0-9]){2}) that I need to validate the input of a text field against when the user clicks the OK button or moves the cursor to another field. That I know how to do, writing the code. However, I’m interested in if itR…
Speeding up Tomcat in debug mode with Eclipse IDE
Running Tomcat through eclipse works fine in non-debug mode, but not in debug mode. When I try to start the Tomcat server in debug mode, the console output looks fine for a while, but then starts slowing down and eventually just stops, pegging the cpu at 100%. I don’t think it’s relevant, but just…