java

different WAR files, shared resources

Suppose you have several applications which share the same code and most of the other resources, but have a somewhat different look and feel, some labels change, etc. (think branding). If each web app is to go in its own WAR file, where do you put the shared resources? I already use the classpath to share classes and property files. Bu...

Need a way to check status of Windows service programmatically

Here is the situation: I have been called upon to work with InstallAnywhere 8, a Java-based installer IDE, of sorts, that allows starting and stopping of windows services, but has no built-in method to query their states. Fortunately, it allows you to create custom actions in Java which can be called at any time during the installation...

Java Strings: "String s = new String("silly");"

I'm a C++ guy learning Java. I'm reading Effective Java and something confused me. It says never to write code like this: String s = new String("silly"); Because it creates unnecessary String objects. But instead it should be written like this: String s = "No longer silly"; Ok fine so far...However, given this class: public final ...

Which JavaScript library you recommend to use with J2EE + Struts + iBatis ?

Which JavaScript library you recommend to use with J2EE + Struts + iBatis ? Something like Ext JS, Dojo, frameworks that can be easily integrated with Struts. ...

Accessing Java annotations from a Taglet

I'm working on a project where we have some custom Taglet classes that are used to modify the Javadocs (such as linking to source code in SVN, adding citations) and so on.One of the things we'd like to do is to be able to get the annotations that are used in the source and manipulate the information from them. It seems that the Taglet ...

"Session closed" error when trying to get a blob from DB using getBinaryStream()

I'm using Hibernate 3.1 and Oracle 10 DB. The blob is defined as @Lob @Basic @Column in the Hibernate entity which corresponds to the relevant DB table. The error -java.sql.SQLException: Closed Connection- seem to appear once in while, not in every attempt to get the blob from the DB. This seems like a hibernate fetching issue, so I tho...

Testing linear class relationship

I'm calling this linear class relationship, but correct me if I'm wrong. I'm looking to test whether or not the class of object A is an ancestor or descendant of object B's class. For example, AbstractCollection is linearly related to both Object and ArrayList. However, ArrayList is not linearly related to Vector. My first stab was: /...

Velocity: $display.list() and a collection of objects.

Velocity DisplayTool has a useful method: $display.list($list) That will format a collection or array into the form "A, B and C". The problem is lets say I have an ArrayList of objects, how do I output a specific object field instead of the whole object? For example the regular loop would look like this: #foreach($obj in $list) ...

How can I set up an LDAP connection pool in a JEE Container?

I need to put an LDAP contextSource into my JEE container's JNDI tree so it can be used by applications inside the container. I'm using Spring-LDAP to perform queries against ORACLE OVD. For development, I simply set up the contextSource in the Spring xml configuration file. For production, however, I need to be able to use a JNDI looku...

Any good Java Swing Timeline Widget?

Is anybody aware of a good Java Swing Timeline Widget with features comparable to the Janus Winforms timeline component? ...

Programatically calculate the size of a value type

I'm writing a unit test for a method that packs boolean values into a byte. The various bit locations are determined by the value of an enum, which only has 5 values right now, but it's conceivable (though extremely unlikely) that this number could go to 9. I'd like a simple test along the lines of: private byte m_myNum; enum MyEnum {...

Access JSTL tag from code inside of forEach loop

Is it possible to access JSTL's forEach variable via code from within the loop? <c:forEach items="${elements}" var="element"> <% element.someMethod(); %> </c:forEach> ...

Which one is better for schema to code generation, XMLBeans or JAXB?

Want to use a library for XML schema to code generation and wanted to know if people have a preference between XMLBeans and JAXB. Performance, Schema validation capability, Memory Usage.. Any indicators will help.. ...

Parsing XML with REGEX in Java

Given the below XML snippet I need to get a list of name/value pairs for each child under DataElements. XPath or an XML parser cannot be used for reasons beyond my control so I am using regex. <?xml version="1.0"?> <StandardDataObject xmlns="myns"> <DataElements> <EmpStatus>2.0</EmpStatus> <Expenditure>95465.00</Expenditure> ...

Static initializer in Java

My question is about one particular usage of static keyword. It is possible to use static keyword to cover a code block within a class which does not belong to any function. For example following code compiles: public class Test { private static final int a; static { a = 5; doSomething(a); } private s...

Write XML file (using XStream) to filesystem in Java

I need to be able to serialize a string and then have it save in a .txt or .xml file. I've never used the implementation to read/write files, just remember I am a relative beginner. Also, I need to know how to deserialize the string to be printed out in terminal as a normal string. ...

Collision Detection between two images in Java

I have two characters displayed in a game I am writing, the player and the enemy. defined as such: public void player(Graphics g) { g.drawImage(plimg, x, y, this); } public void enemy(Graphics g) { g.drawImage(enemy, 200, 200, this); } Then called with: player(g); enemy(g); I am able to move player() around with the keyboa...

Unit testing code that sends JMS messages

i have a class that after it does some stuff, sends a JMS message. i'd like to unit test the "stuff", but not necessarily the sending of the message. when i run my test, the "stuff" green bars, but then fails when sending the message (it should, the app server is not running). what is the best way to do this, is it to mock the message qu...

Building a scala app with maven (that has java source mixed in)

I have an application where I would like to have mixed Java and Scala source (actually its migrating a java app to scala - but a bit at a time). I can make this work in IDEs just fine, very nice. But I am not sure how to do this with maven - scalac can compile java and scala intertwined, but how to I set up maven for the module? Also...

Java TreeMap sorting options?

I've been told that the java class TreeMap uses an implementation of a RB tree. If this is the case, how does one do an inorder, preorder and postorder tree-walk on a TreeMap? Or is this not possible? ...