java

How do I execute Ant command if some task fails?

Suppose I have some Ant task, say javac or junit. If either task fails, I want to execute a command, but if they succeeds I don't. Any idea how to do this? ...

Fastest way of checking the condition l+1<r for int l,r in Java

What is the fastest way of checking the condition l + 1 < r for int l,r in Java? l and r are not constant and I know that l <= r. The comparison is a stopping condition for a while loop in a binary search implementation. I am of course benchmarking my code, both in a separate test (searching a large array) and in the code which uses ...

Why passing {a, b, c} to a method doesn't work ?

Hello, I've tried to pass an initialization list {...} to a constructor and it didn't work. When I instead declared it in a method local variable (int[]) it worked flawlessly. Why is that? public class QuickSort { int[] a; public QuickSort(int[] a) { this.a = a; } public static void main(String[] args) { //...

HTML form submission from java requires cookies and a popup blocker

I am using POST to submit a form to a web-based login server from a java application. However, the webpage requires both cookies and a popup blocker, which are detected and handled in an init() javascript function: if (document.cookie == "") { alert("Cookies are disabled. Cannot access server with this setting.\nPlease configur...

Removing JGroups startup message : GMS

On startup JGroups 2.7.0. GA writes to System.out a message along the lines of: --------------------------------------------------------- GMS: address is 10.0.3.35:48641 (cluster=blabla) --------------------------------------------------------- I want to either suppress it or redirect it using Log4j ( which the rest of the framework u...

Are there wrappers for the Actionscripts's LocalConnection for C# or Java?

Hi, I want to communicate with the LocalConnection framework of Flash via C#/Java/C++. My search for already implemented wrappers was not as successfull as I wish ;). There exist several servers (like FluorineFx) which support binding of C# objects to the LocalConnection. The problem is I am not looking for a server but only for a simpl...

How to expose Red5's SharedObjects through SOAP

Edit: Obviously my first question was not really easy to understand, I hope the answer is usefull :) I have tried installing Axis2 on the Red5 server and everything went ok, I accessed the Red5 app properties from a custom Web Service using Red5's RTMPClient and exposed them through Axis2. The problem is that doing it that way I have a...

JSP to serve a zip corrupts the file

I'm having a problem trying to serve a zip file in a JSP. The zip file is always corrupt after it has finished downloading. I've tried a few different methods for reading and writing, and none of them seem to do the trick. I figure it is probably adding in ascii characters somewhere as the file will open and display all the filena...

Ant task for generating ER diagram from JPA/Hibernate annotated classes

Does anyone know of a tool that can do that? Linguine maps seems to only work on old hibernate xml files. And the hibernate tool task hbm2hbmxml seems to have a bug so that I can't do the two step process "annotations->hbmxml->diagram" Best, Anders ...

How to build a Java Servlet in Eclipse?

I'm new to Java. I have to modify this Web Servlet that is running on my Tomcat. The Webapps folder contains several files and directories, but only one .JAR file. I managed to decompile it using Java Decompiler JD-GUI, but when I create the project in Eclipse from the decompiled source and try to Validate it, Eclipse shows me around 389...

Reusing a PreparedStatement

I ran findbugs on our code base and it pointed out there are two more Statements that still need to be closed. In this section of the code we run: preparedStatement = connection.prepareStatement(query); for 3 different queries, reusing preparedStatement. In the finally block we do close the resource: finally{ try{ if (resu...

Uploading multiple images onto a panel in Java.

Hi everyone, I'm trying to upload multiple images onto a panel but I don't just know how to do this. I can upload a single image but not more than one at a time. Actually I need this knowledge to make a simple card game I recently designed look more real. Can anyone help me out. ...

Shared Library for iPhone and BlackBerry

I have a set of functionality (classes) that I would like to share with an application I'm building for the iPhone and for the Blackberry (Java). Does anyone have any best practices on doing this? ...

Can I set Java max heap size for running from a jar file?

I am launching a java jar file which often requires more than the default 64MB max heap size. A 256MB heap size is sufficient for this app though. Is there anyway to specify (in the manifest maybe?) to always use a 256MB max heap size when launching the jar? (More specific details below, if needed.) This is a command-line app that ...

Java equivalent for PHP's mysql_real_escape_string()

Is there a Java equivalent to PHP's mysql_real_escape_string() ? This is to escape SQL injection attempts before passing them to Statement.execute(). I know I can use PreparedStatement instead, but let's assume these are one shot statements so preparing them will result in lower performance. I've already changed the code to use Prepare...

Display different Tomcat error pages depending on URL of original request

I would like to use Tomcat's error-page directive to display various different error pages in response to various types of exceptions. However, I want the error page displayed to have different styling and content depending on the original request URL that resulted in the error. Specifically, I have an admin part of my web application,...

White papers and books on programming for performance in Java

I'm looking for a white paper or online book/tutorial about coding efficiently in Java. I've read the white paper from Sun on Performance Tuning (which was mostly about JVM settings) and the one about Garbage Collection management. I'm looking for a paper that focuses more at the code level - which types of constructs are more efficient ...

How to set action scope in struts 2

In struts the action scope was defined as <action scope="session" .../> How do you set the scope in Struts2? ...

How do I enable RDS support for BlazeDS?

I'm using BlazeDS 3 in my application. The dependencies for the BlazeDS libraries are downloaded from a public maven repository. However I can't enable the RDS support on the server because of some missing library. Does anyone know where this class is located: flex.rds.server.servlet.FrontEndServlet in the blazeds distribution? ...

How to convert object array to string array in Java

I use the following code to convert an object array to a string array : Object Object_Array[]=new Object[100]; // ... get values in the Object_Array String String_Array[]=new String[Object_Array.length]; for (int i=0;i<String_Array.length;i++) String_Array[i]=Object_Array[i].toString(); But I wonder if there is another way to do thi...