java

A simple way to create static imports for constants in existing code?

If I have a constant BAR in Foo, which I will use in a class C I'll have to write Object o = Foo.BAR + "..."; which I can use Ctrl-Shift-M in Eclipse to create a static import for like: import static Foo.BAR; Object o = BAR + "...."; I am current updating legacy code with literaly thousands of these I'd like to convert to static i...

Accurate Sleep for Java on Windows

Does anyone know a Library which provides a Thread.sleep() for Java which has an error not higher than 1-2 Millisecond? I tried a mixture of Sleep, error measurement and BusyWait but I don't get this reliable on different windows machines. It can be a native implementation if the implementation is available for Linux and MacOS too. ...

How can I use Java to programmaticaly convert an Internal Stylesheet of a web-page to an inline one?

Is there a ready-made tool or utility that does that already ...

executing a class in remote jvm

Hi All, I have a small test class that i want to run on a particular jvm that's already up and running (basically it's an web application running on Tomcat) . The reason i want to do this is i want to execute a small test class (with the main method and all) within that jvm so that i get the same environment (loaded and initialized cl...

Good books or online resources for learning Hibernate

What I found so far are some online resources like this: http://www.torsten-horn.de/techdocs/java-hibernate.htm (GER) https://www.hibernate.org/5.html (Hibernate Docs) http://docs.jboss.org/hibernate/stable/core/reference/en/html/tutorial.html http://www.manning.com/bauer2/chapter2.pdf (Sample chapter of Java Persistence with Hiberna...

Should methods that throw RuntimeException indicate it in method signature?

For example, many methods in frameworks/JDK might throw java.lang.SecurityException but this is not indicated in the method signature (since that is a practice normally reserved for checked exceptions). I want to argue that declaring RuntimeExceptions in method sigs has many benefits (akin to static type checking for example). Am I d...

Grails query association problem

Hi, I'm having trouble writing a query for the following domain classes: class Person { static hasMany = [memberships: Membership] } class Membership { static belongsTo = [person: Person, group: Group] Date joinDate = new Date(); Group group; Person person; } class Group { static hasMany = [memberships: Member...

How to route to the nearest RMI Server?

In continuation to my question How to improve the performance of client server architecture application I have decided to maintain a centralized database and several slave server-database configuration. I plan to use Symmetric DS for replicating between the slave and master database. Each server-database configuration would be installed...

mysql driver jar not being recognized

Hi all, I have an token class file in an jar file. The token class files is the class that uses jdbc to retrieve data from the database. However when I call the jar file it does not seem to recoginize the external mysql driver jar file. The error is pointed to this line Class.forName(driver);. I have referenced the mysql driver in...

What happens to all the hard-coded URIs when I move a Web Service?

I'm developing a test WS with JAX-WS and the demo works fine but if I try to move it in production there are a lot of occurences of the URL of my test enviroment on my code. For example: com.mycompany.testserver.ws.writer.WriterInterface service = new com.mycompany.testserver.ws.writer.WriterInterface(); QName portQName = new QName("ht...

Reading a CSV file into Java as a DB table

I've found numerous posts about reading CSV with Java and the APIs they were pointing at all had a line-oriented approach when it came to reading a CSV file. Something like "while you get a line, get the values of every column". I'd appreciate a higher-level API, like in Perl where DBI allows you to use SQL on CSV like if it where a DB ...

Saving bidirectional ManyToMany

I have two entity classes annotated in the following way @Entity class A { @ManyToMany(mappedBy="A", cascade=CascadeType.ALL) private List<B> b; .. } @Entity class B { @ManyToMany(cascade=CascadeType.ALL) private List<A> a; .. } If I store an instance of the class 'B', the relations are stored in the database and the g...

Using Spring AOP in an JSF application

consider a JSF web application with a managed bean FooBean.java. I've declared this "FooBean" in my faces-config.xml file. Now, if I want to add the Spring AOP advice for the methods of FooBean, how do I do that? Should I add an applicationContext.xml file and declare the managed beans inside it? or will it work even if I am not decl...

Recommended usage of Spring's @Required annotation

I see that Spring has a @Required annotation to mark member variables in beans that must be set. Is there a best practice for using this? For instance, might it be better to set these values in the constructor and make these parameters explicitly required (esp. when used outside of Spring)? Thanks! ...

Best practices for installing 3rd party libraries into your hosted Maven repository?

Let's say that you have a project which is using a 3rd party library, such as Google's Analytics Data API (gdata), which does not appear to be currently deployed into any well-known or popular Maven public repositories/indexes. This isn't much of a problem, as I can just deploy the artifact into my local hosted Nexus repository. But, ar...

What do I need to download to start developing apps using the Spring framework?

I need to start developing applications using the Spring framework, and am wondering what tools I need to download to have me up and running. On the SpringSource website I am seeing all these applications to download and I am wondering, do I really need all this? And what versions should I use, especially for Spring Framework? Spring...

Spring Security: Advice needed on how to handle GrantedAuthority

I have a concern when it comes to GrantedAuthority objects in a Spring Security application. I'm looking for a good way to handle things. First of all I'm trying to describe my concern, if there are any factual errors do not hesitate to point them out, I'll only be greatful. Spring Security uses GrantedAuthority instances to act as toke...

What applications do i need to download to start developing apps using spring framework?

Guys, I need to start developing applications using spring framework, and am wondering what tools do i need to download to have me up and running. On the springsourcewebsite am seeing all this applications to download and am wondering do i really need all this? And what versions should i use, especially for Spring Framework? * Spring...

Lucene performance

Hi guys, could you please suggest on the steps to be followed for lucene performance. especially with large data (around 1TB of pdf files to be indexed) ...

How to connect a Java back end with a .NET front end

Hi, I have a bunch of Java code which was written using the Hibernate framework, originally destined to have a front end written using JSPs. However, the requirements for the front end have changed, and we've decided that a desktop client (which will be written in .NET) is a better match for our users. I don't really want to waste the ...