Tag Archives: java

JBoss remote debug

To connect to JBoss application server remotely you should perform next action:

open run.conf.bat (for windows) or run.conf (for linux) file in JBoss bin folder
and add the following java argument:

JAVA_OPTS="$JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"

If you miss -Xdebug parameter you can enter to debug mode but after timeout (a few minutes) you’ll be disconnected and JBoss restart occurred!
Read more at http://stackoverflow.com/questions/18182666/eclipse-remote-debugging-with-jboss.

Thanx to http://stackoverflow.com/a/18211332

Could not transfer artifact with Maven

You may see the error when try to make maven project:
Could not transfer artifact Connection refused: connect

The problem may be with your internet connection and can be fixed by adding the following settings in maven settings.xml file (for windows: %USERPROFILE%\.m2 folder):


Thanx to http://stackoverflow.com/a/16729906.

Trim string in Java

Don’t like string frameworks? Use POJO java!

static String trim(String value, char character) {
    if (value == null || value.isEmpty()) {
        return value;
    String normalized = value.trim();

    int startIndex = 0;
    while (normalized.charAt(startIndex) == character) {

    int endIndex = value.length() - 1;
    while (normalized.charAt(endIndex) == character) {

    return normalized.substring(startIndex, endIndex + 1).trim();


Why JavaEE ?

Why JavaEE is so popular? Not because it is the super useful, just this is implementation of all incoming business requirements for a time. This is so called template patterns for business, nothing more: not technical brilliance, not ideological concern.

Here is high availability, high scalability, high reliability platform for building business infrastructure.
The time from first release is a proof.
Use java!

Floating point operations in XPath

You may need to perform arithmetic operation with XPath-expression like sum, etc. But Saxon parser cast all floating point values to DOUBLE by default (as Java).
If you have next xml:


So, for sum you use next XPath expression:


And in result you’ll have NOT 1.555, but 1.4999999754 for example.
This is normal java behavior! Don’t panic!
Just use some trick:


And it gives you 1.555 in result.

As you see, adding /xs:decimal(.) solves the problem with data losses.

Capitalize word algorithm in Java

Here is simple snippet to capitalize string:

private static String capitalize(String value) {
    return value == null ? null : 
        value.substring(0, 1).toUpperCase() + value.substring(1);


Thanx to

Using binding in JSF

You may heard about binding term in JSF. But it can be used?
Binding can be involved in validation procedure.

1. Add form to JSF page:

    <h:inputText id="email" 
        binding="#{SomeBaen.emailComponent}" />
    <h:message for="email" />

    <h:commandButton value="Check" action="#{SomeBaen.doCheck}" />

2. Create bean:

public class SomeBean implements Serializable {
    private static final long serialVersionUID = 1L;
    private String emailValue;
    private UIComponent emailComponent;
    public String doCheck() {
        if (isValid(emailValue)) {
            return "ok";
        // set invalid message
        FacesMessage message = new FacesMessage("Invalid email");
        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(emailComponent.getClientId(context), message);
        return null;
    public void setEmailValue(String emailValue) {
        this.emailValue = emailValue;
    public String getEmailValue() {
        return emailValue;
    public void setEmailComponent(UIComponent emailComponent) {
        this.emailComponent = emailComponent;
    public UIComponent getEmailComponent() {
        return emailComponent;

So, if validation failed you’ll see a message near inputText control.
Also example http://stackoverflow.com/a/321722