Skip to content

How to use String as Velocity Template?

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…

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…

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…