Wednesday, October 17, 2012

How to eliminate switches and enums with simple polymorphism

Hi there! Today we will see, based on a real example, how we can banish ugly switch-cases and enums from the code with simple polymorphism. The example bellow has been written by my self a few months ago. At this time i was convinced that it was simple and good enough. Now i know it better and i'm convinced that it could be better, more flexible and maintainable with little effort but with huge effect. The following example handles states of buttons in a game field i'm programming.


UML




Interface EnableDisable



import java.util.List;

import javax.swing.JButton;

public interface EnableDisable {

    public void disableButtons(List<JButton> gameFieldButtons, int... indizes);

    public void disableButtons(JButton selectedButton, List<JButton> gameFieldButtons, int... steps);

    public void enableButtons(List<JButton> gameFieldButtons, int... indizes);

    public void enableButtons(JButton selectedButton, List<JButton> gameFieldButtons, int... steps);

}

Class EnableDisableUtil

import java.awt.Color;
import java.util.List;

import javax.swing.JButton;
import javax.swing.border.LineBorder;

public class EnableDisableUtil implements EnableDisable {

    public void disableButtons(List<JButton> gameFieldButtons, int... indizes) {
        disableOrEnable(Choice.DISABLE, gameFieldButtons, indizes);
    }

    public void disableButtons(JButton selectedButton, List<JButton> gameFieldButtons, int... steps) {
        disableOrEnable(Choice.DISABLE, selectedButton, gameFieldButtons, steps);
    }

    public void enableButtons(List<JButton> gameFieldButtons, int... indizes) {
        disableOrEnable(Choice.ENABLE, gameFieldButtons, indizes);
    }

    public void enableButtons(JButton selectedButton, List<JButton> gameFieldButtons, int... steps) {
        disableOrEnable(Choice.ENABLE, selectedButton, gameFieldButtons, steps);
    }

    private void disableOrEnable(Choice choice, List<JButton> gameFieldButtons, int... indizes) {
        switch (choice) {
        case ENABLE:
            for (int i = 0; i < indizes.length; i++) {
                enable(indizes[i], gameFieldButtons);
            }
            break;
        case DISABLE:
            for (int i = 0; i < indizes.length; i++) {
                disable(indizes[i], gameFieldButtons);
            }
            break;
        default:
            break;
        }

    }

    private void disableOrEnable(Choice choice, JButton selectedButton, List<JButton> gameFieldButtons, int... steps) {
        for (int i = 0; i < steps.length; i++) {
            int valueFromSelectedButton = Integer.valueOf(selectedButton.getText());
            int valueFromButtonToBeDisabled = steps[i] + valueFromSelectedButton;
            int indexFromButtonToBeDisabled = valueFromButtonToBeDisabled - 1;// because gameFieldButtons starts by 0
            switch (choice) {
            case ENABLE:
                enable(indexFromButtonToBeDisabled, gameFieldButtons);
                break;
            case DISABLE:
                disable(indexFromButtonToBeDisabled, gameFieldButtons);
                break;
            default:
                break;
            }
        }
    }

    private void enable(int buttonIndex, List<JButton> gameFieldButtons) {
        JButton buttonToBeDisabled = gameFieldButtons.get(buttonIndex);
        buttonToBeDisabled.setEnabled(true);
        buttonToBeDisabled.setBorder(new LineBorder(Color.red, 1, false));
    }

    private void disable(int buttonIndex, List<JButton> gameFieldButtons) {
        JButton buttonToBeDisabled = gameFieldButtons.get(buttonIndex);
        buttonToBeDisabled.setEnabled(false);
        buttonToBeDisabled.setBorder(new LineBorder(Color.lightGray, 1, false));
    }

    private enum Choice {
        ENABLE, DISABLE;
    }

}

What are we doing in this example?

Well, here i'm disabling or enabling some gameFields from my application depending on the method i call. (public methods). Now my question: What's wrong with that? It seems to be pragmatic for this simple use case, right? Well although at first glance this use case seems plausible and functionally ok(it passes the unit test), this design has potential for improvement. Let's point out first what i did "wrong":
  • The name of my interface is not smart. It implies more then one responsabilities.
  • I repeat myself in the signature of the methods of EnableDisable. Only the parameters are different
  • The enum and switches signals fix states to me. So it would be better to handle it over polymorphie.

Let's do the changes. First i wanna rename my interface from EnableDisable to Switchable and let's also eliminate 2 methods. In the sequence let's declare 2 classes called SwitchOn and SwitchOff.


Nice! Thats a lot more interesting. But let's take a look at the concrete classes SwitchOn and SwitchOff to be able to decide if it is good this way or not.

import java.util.List;
import javax.swing.JButton;

public interface Switchable {

    public void toSwitch(List<JButton> gameFieldButtons, int... indizes);

    public void toSwitch(JButton selectedButton, List<JButton> gameFieldButtons, int... steps);

} 


import java.awt.Color;
import java.util.List;
import javax.swing.JButton;
import javax.swing.border.LineBorder;

public class SwitchOn implements Switchable {

    @Override
    public void toSwitch(List<JButton> gameFieldButtons, int... indizes) {
        switchOn(gameFieldButtons, indizes);
    }

    @Override
    public void toSwitch(JButton selectedButton, List<JButton> gameFieldButtons, int... steps) {
        switchOn(selectedButton, gameFieldButtons, steps);
    }

    private void switchOn(JButton selectedButton, List<JButton> gameFieldButtons, int... steps) {
        for (int i = 0; i < steps.length; i++) {
            int valueFromSelectedButton = Integer.valueOf(selectedButton.getText());
            int valueFromButtonToBeDisabled = steps[i] + valueFromSelectedButton;
            int indexFromButtonToBeDisabled = valueFromButtonToBeDisabled - 1;// because gameFieldButtons starts by 0
            enable(indexFromButtonToBeDisabled, gameFieldButtons);
        }
    }

    private void switchOn(List<JButton> gameFieldButtons, int... indizes) {
        for (int i = 0; i < indizes.length; i++) {
            enable(indizes[i], gameFieldButtons);
        }
    }

    private void enable(int buttonIndex, List<JButton> gameFieldButtons) {
        JButton buttonToBeDisabled = gameFieldButtons.get(buttonIndex);
        buttonToBeDisabled.setEnabled(true);
        buttonToBeDisabled.setBorder(new LineBorder(Color.red, 1, false));
    }
} 


import java.awt.Color;
import java.util.List;
import javax.swing.JButton;
import javax.swing.border.LineBorder;

public class SwitchOff implements Switchable {

    @Override
    public void toSwitch(List<JButton> gameFieldButtons, int... indizes) {
        switchOff(gameFieldButtons, indizes);
    }

    @Override
    public void toSwitch(JButton selectedButton, List<JButton> gameFieldButtons, int... steps) {
        switchOff(selectedButton, gameFieldButtons, steps);
    }

    private void switchOff(JButton selectedButton, List<JButton> gameFieldButtons, int... steps) {
        for (int i = 0; i < steps.length; i++) {
            int valueFromSelectedButton = Integer.valueOf(selectedButton.getText());
            int valueFromButtonToBeDisabled = steps[i] + valueFromSelectedButton;
            int indexFromButtonToBeDisabled = valueFromButtonToBeDisabled - 1;// because gameFieldButtons starts by 0
            disable(indexFromButtonToBeDisabled, gameFieldButtons);
        }
    }

    private void switchOff(List<JButton> gameFieldButtons, int... indizes) {
        for (int i = 0; i < indizes.length; i++) {
            disable(indizes[i], gameFieldButtons);
        }
    }

    private void disable(int buttonIndex, List<JButton> gameFieldButtons) {
        JButton buttonToBeDisabled = gameFieldButtons.get(buttonIndex);
        buttonToBeDisabled.setEnabled(false);
        buttonToBeDisabled.setBorder(new LineBorder(Color.lightGray, 1, false));
    }
} 


Don't Repeat Yourself (DRY)

Well as we can see this is a lot better but we can still see a lot of dupplicated code inside of it. The only difference in the implementation from SwitchOn or SwitchOff is the setEnable(true) or setEnable(false) in the methods enable(...) or disable(...) and the LineBorder of both. Let's do one more elegant change to it like this:


import java.util.List;
import javax.swing.JButton;
import javax.swing.border.LineBorder;

public abstract class SwitchAbstract implements Switchable {
 @Override
 public void toSwitch(List<JButton> gameFieldButtons, int... indizes) {
  switchWithIndex(gameFieldButtons, indizes);
 }
 @Override
 public void toSwitch(JButton selectedButton, List<JButton> gameFieldButtons, int... steps) {
  switchWithSteps(selectedButton, gameFieldButtons, steps);
 }
 private void switchWithIndex(List<JButton> gameFieldButtons, int... indizes) {
  for (int i = 0; i < indizes.length; i++) {
   turnSwitchTo(indizes[i], gameFieldButtons);
  }
 }
 private void switchWithSteps(JButton selectedButton, List<JButton> gameFieldButtons, int... steps) {
  for (int i = 0; i < steps.length; i++) {
   int valueFromSelectedButton = Integer.valueOf(selectedButton.getText());
   int valueFromButtonToBeSwitched = steps[i] + valueFromSelectedButton;
   int indexFromButtonToBeSwitched = valueFromButtonToBeSwitched - 1;// because gameFieldButtons starts by 0
   turnSwitchTo(indexFromButtonToBeSwitched, gameFieldButtons);
  }
 }
 private void turnSwitchTo(int buttonIndex, List<JButton> gameFieldButtons) {
  JButton buttonToSwitch = gameFieldButtons.get(buttonIndex);
  buttonToSwitch.setEnabled(switchTo());
  buttonToSwitch.setBorder(howShallLineBorderLooksLike());
 }
 protected abstract boolean switchTo();
 protected abstract LineBorder howShallLineBorderLooksLike();
} 


public class SwitchOn extends SwitchAbstract {
 @Override
 protected boolean switchTo() {
  return Boolean.TRUE;
 }
 @Override
 protected LineBorder howShallLineBorderLooksLike() {
  return new LineBorder(Color.red, 1, false);
 }
} 


public class SwitchOff extends SwitchAbstract {
 @Override
 protected boolean switchTo() {
  return Boolean.FALSE;
 }
 @Override
 protected LineBorder howShallLineBorderLooksLike() {
  return new LineBorder(Color.lightGray, 1, false);
 }
} 

Why did i name the class SwitchAbstract and not AbstractSwitch?

Well maybe you did not noticed or it is not so obvious at first sight, but i has a good reason. the reason is in the way i'm able to search in my IDE. Naming my classes this way alls "Switch..." classes will be presented as a list in a very nice way while looking for the keyword "switch" in Eclipse. 



Results in facts:

When talking about clean code i ofen hear the argumet: It makes my code a lot more complex and generate a lot of useless code. Well let's see if this is true. I have more classes. For this case it must be automatically more complex and of course it must be have generated more lines of code right? 

Old version: Lines of code:  96 Lines of code 
New version: Lines of code: 73 Lines of code

Old class and interface names: Naming was not that simple understandable.
New class and interface names: Clear, does not implies more then one responsabilities

Old class implementation: Costs a lot and had ugly switch-cases and enums in it.
New class implemention: No effort, no enums, no ungly switche-cases  

😱👇 PROMOTIONAL DISCOUNT: BOOKS AND IPODS PRO ðŸ˜±ðŸ‘‡

Be sure to read, it will change your life!
Show your work by Austin Kleonhttps://amzn.to/34NVmwx

This book is a must read - it will put you in another level! (Expert)
Agile Software Development, Principles, Patterns, and Practiceshttps://amzn.to/30WQSm2

Write cleaner code and stand out!
Clean Code - A Handbook of Agile Software Craftsmanship: https://amzn.to/33RvaSv

This book is very practical, straightforward and to the point! Worth every penny!
Kotlin for Android App Development (Developer's Library): https://amzn.to/33VZ6gp

Needless to say, these are top right?
Apple AirPods Pro: https://amzn.to/2GOICxy

😱👆 PROMOTIONAL DISCOUNT: BOOKS AND IPODS PRO ðŸ˜±ðŸ‘†


Saturday, October 13, 2012

Understanding Dependency Inversion in real life


Hi there! Today i wanna share a real life example of dependency Inversion with you. In my RCP-Client developer career we had often the challange that due some customer change requests, we were forced to instantiate some domain specific dialogs from base. The problem here is that base (package: com.yourcompany.base) is not allowed to create dependencies to domain specific packages. So how could we solve this problem? We must inverse the dependency. What do we need? We will create a dependency registry in which we register domain specific dialog factories to be able to instantiate them from the base without having to create dependencies from base to specific domain packages.

The common factory interface

We define a factory interface in base. Let's say package is called: com.yourCompany.base.



interface DialogFactory{
    Dialog createFilterDialog();
}

In the same package we define an interface for the depencency inversion of our registry later:

// then we define also in base the interface for DependencyInversion in general. 
// to be used by all Registries we need in future. package: com.yourCompany.base
public interface DependencyInversion<T> {

    void registerFactory(String factoryMapKey, T factory);

    void unregisterFactory(String factoryMapKey);

    T getRegisteredFactoryOrNull(String factoryMapKey);
}

Now we need a Dependency Inversion Helper, which will handle the factory map later:


import java.util.HashMap;
import java.util.Map;

// for the same general reason, we define a dependency inversion helper which
// handle with the factoryMaps for any kind of factory in future. This class is
// also placed in base package: com.yourCompany.base
public class DependencyInversionHelper<T> {

    private Map<String, T> factoryMap = new HashMap<String, T>();

    public void unregisterIfExistsInMap(String factoryMapKey) {
        if (doesFactoryExistInMap(factoryMapKey)) {
            removeFactoryFromMap(factoryMapKey);
        }
    }

    public void registerIfNotExistsInMap(String factoryMapKey, T factory) {
        if (!doesFactoryExistInMap(factoryMapKey)) {
            insertFactoryIntoMap(factoryMapKey, factory);
        }
    }

    public boolean doesFactoryExistInMap(String factoryMapKey) {
        return this.factoryMap.containsKey(factoryMapKey);
    }

    public void insertFactoryIntoMap(String factoryMapKey, T factory) {
        this.factoryMap.put(factoryMapKey, factory);
    }

    public void removeFactoryFromMap(String factoryMapKey) {
        this.factoryMap.remove(factoryMapKey);
    }

    public T getRegisteredFactoryOrNull(String factoryMapKey) {
        return (T) (doesFactoryExistInMap(factoryMapKey) ? this.factoryMap.get(factoryMapKey) : null);
    }

}

The Registry

And finally we define in the same package our registry, which uses the helper and implements DependencyInversion:


// Now every thing we need to implement is the registry itself. This will be a singleton because
// we just need it once in the whole application. We place it also in base: com.yourCompany.base 
public class FilterDialogDependencyInversionRegistry implements DependencyInversion<DialogFactory> {

    private static FilterDialogDependencyInversionRegistry instance = new FilterDialogDependencyInversionRegistry();
    private DependencyInversionHelper<DialogFactory> helper = new DependencyInversionHelper<DialogFactory>();

    private FilterDialogDependencyInversionRegistry() {
        // singleton: we just need one global registry for it.
    }

    public static FilterDialogDependencyInversionRegistry instance() {
        return instance;
    }

    @Override
    public void registerFactory(String factoryMapKey, DialogFactory factory) {
        helper.registerIfNotExistsInMap(factoryMapKey, factory);
    }

    @Override
    public void unregisterFactory(String factoryMapKey) {
        helper.unregisterIfExistsInMap(factoryMapKey);
    }

    @Override
    public DialogFactory getRegisteredFactoryOrNull(String factoryMapKey) {
        return helper.getRegisteredFactoryOrNull(factoryMapKey);
    }

}

Ready for implementation:

Now we are able to register all factories we need with this registry. Because this registry is visible in base and in any other domain specific package, we can access our new Registry from anywhere and get the factory we need for any factoryMapKey we define. In Eclipse RCP this is usually done in the method  start() from the application. when the method getRegisteredFactoryOrNull(key) is called, we get a  DialogFactory and are able now to call the method createFilterDialog() from it. What it happens now is very cool. Any interface knows its implementation and creates the right dialog without having dependencies to the base modul. Any domain specific factory must only implement DialogFactory. That's all.

😱👇 PROMOTIONAL DISCOUNT: BOOKS AND IPODS PRO ðŸ˜±ðŸ‘‡

Be sure to read, it will change your life!
Show your work by Austin Kleonhttps://amzn.to/34NVmwx

This book is a must read - it will put you in another level! (Expert)
Agile Software Development, Principles, Patterns, and Practiceshttps://amzn.to/30WQSm2

Write cleaner code and stand out!
Clean Code - A Handbook of Agile Software Craftsmanship: https://amzn.to/33RvaSv

This book is very practical, straightforward and to the point! Worth every penny!
Kotlin for Android App Development (Developer's Library): https://amzn.to/33VZ6gp

Needless to say, these are top right?
Apple AirPods Pro: https://amzn.to/2GOICxy

😱👆 PROMOTIONAL DISCOUNT: BOOKS AND IPODS PRO ðŸ˜±ðŸ‘†

Understanding Callbacks with Java - Inversion of control

Callback Pattern in Java Environment


Hi there! today i wanna share something with you, that it is very common and widely used in javascript for example. I'm speaking of callbacks. Do you know how and when this "pattern" is used? Do you really understand it in a java context (environment)? Well i was asking me also some of those questions and that's the reason i started to learn more about it. The ideia behind it is the inversion of control (abbreviated IoC). This paradigma describes the way frameworks work. It is also known as the "Hollywood principle - Don't call me, we will call you"

Simplified Callback pattern in Java just to understand it. Concrete example follows bellow.




interface CallBack {
    void methodToCallBack();
}

class CallBackImpl implements CallBack {
    public void methodToCallBack() {
        System.out.println("I've been called back");
    }
}

class Caller {

    public void register(CallBack callback) {
        callback.methodToCallBack();
    }

    public static void main(String[] args) {
        Caller caller = new Caller();
        CallBack callBack = new CallBackImpl();
        caller.register(callBack);
    }
} 

Ok you may be asking you, when this usefull or may be asking you what's the difference between calling directly callback.methodToCallBack() right?

ANSWER: well, this example just shows to you how to construct such a callBack function when working in a java environment. Certainlly it doesn't make it any sense to use it that way. Let's get a little deeper into a concrete useful example now.

The idea behind it is the "INVERSION OF CONTROL". Let's take a timer as a realistic example. Let's supose that you know, that a specific timer supports callback functions every hour. Exactly it means, that every hour, the timer will call your registed call method function.

Conctrete Example:

Let's say we wanna update the time of a website every hour. Here is the UML of the following example:


Callback Interface

Let's define first the callback interface:


import java.util.ArrayList;
import java.util.List;

// For example: Let's assume that this interface is offered from your OS to be implemented
interface TimeUpdaterCallBack {
    void updateTime(long time);
}

// this is your implementation.
// for example: You want to update your website time every hour
class WebSiteTimeUpdaterCallBack implements TimeUpdaterCallBack {

    @Override
    public void updateTime(long time) {
        // print the updated time anywhere in your website's example
        System.out.println(time);
    }
}

The SystemTimer that supports Callback functions in our example:



// This is the SystemTimer implemented by your Operating System (OS)
// You don't know how this timer was implemented. This example just
// show to you how it could looks like. How you could implement a
// callback by yourself if you want to.
class SystemTimer {

    List<TimeUpdaterCallBack> callbacks = new ArrayList<TimeUpdaterCallBack>();

    public void registerCallBackForUpdatesEveryHour(TimeUpdaterCallBack timerCallBack) {
        callbacks.add(timerCallBack);
    }

    // ... This SystemTimer may have more logic here we don't know ...

    // At some point of the implementaion of this SystemTimer (you don't know)
    // this method will be called and every registered timerCallBack
    // will be called. Every registered timerCallBack may have a totally
    // different implementation of the method updateTime() and my be
    // used in different ways by different clients.
    public void oneHourHasBeenExprired() {

        for (TimeUpdaterCallBack timerCallBack : callbacks) {
            timerCallBack.updateTime(System.currentTimeMillis());
        }
    }
}

And finally our WebSiteTimeUpdater which is our client in this fictive and simple example:



// This is our client. It will be used in our WebSite example. It shall update
// the website's time every hour.
class WebSiteTimeUpdater {

    public static void main(String[] args) {
        SystemTimer SystemTimer = new SystemTimer();
        TimeUpdaterCallBack webSiteCallBackUpdater = new WebSiteTimeUpdaterCallBack();
        SystemTimer.registerCallBackForUpdatesEveryHour(webSiteCallBackUpdater);
    }
}

😱👇 PROMOTIONAL DISCOUNT: BOOKS AND IPODS PRO 😱👇

Be sure to read, it will change your life!
Show your work by Austin Kleon: https://amzn.to/34NVmwx

This book is a must read - it will put you in another level! (Expert)
Agile Software Development, Principles, Patterns, and Practices: https://amzn.to/30WQSm2

Write cleaner code and stand out!
Clean Code - A Handbook of Agile Software Craftsmanship: https://amzn.to/33RvaSv

This book is very practical, straightforward and to the point! Worth every penny!
Kotlin for Android App Development (Developer's Library): https://amzn.to/33VZ6gp

Needless to say, these are top right?
Apple AirPods Pro: https://amzn.to/2GOICxy

😱👆 PROMOTIONAL DISCOUNT: BOOKS AND IPODS PRO 😱👆

How to configure Jboss 7 - The Essence of JBoss AS 7

How to use and configure JBoss AS 7 on Windows Vista?

Hi there! in this post i wanna share with you some of the new features of JBoss 7. Our company works since years with JBoss (Versions 5, 6 and going to upgrade to 7) As a client developer i didn't have much chance to explore and understand JBoss in deep and details. That's the reason i am diving into the JBoss world extending my know-how a little bit. The books i read are all heavy weights. So i tried to extract the essence of it, making it easy for you and me to get started with and to have a source to look for, when trying to do more specific things with. I will not show or discuss to many architectual designs in deep and things like that. If you are looking for architectual designs in deep, i recommend the book from Francesco Marchioni called: JBoss AS7 Configuration, Deployment and Administration. In this first post, we will see how to install JBoss 7 on windows vista and how to install the JBoss tools with Eclipse as an IDE.

Getting started: Installing the environment. We will do it, step by step don't worry.

  • you'll need the Java Development Kit where JBoss 7 will be running
  • you'll need to install JBoss 7
  • you'll need to install an IDE. In this case eclipse is the best for me.  

Downloading and installing the JDK

go to: Java Development Kit JDK and download the JDK the fits to your PC-Hardware (34Bit or 64Bit)
In my case i'll take the 32bit version: jdk-7u7-windows-i586.exe 



Tip: To find out if your PC is a 32 or 64Bit maschine, do that on windows vista for example: go to: system configuration>system>show. Take a look at this picture bellow:


Attention: As soon as you double click the installer, make sure you define an installation path that do not contain empty spaces. Usually windows will propose you to isnstall the JDK in C:\Program Files. This leads to some issues when you are referencing the core libraries. A better installation path would be C:\Software\Java or even simplier and better C:\Java.

Updating the settings of you PC after the installation of the JDK

The most important setting is the JAVA_HOME environment variable. JBoss is referenced to it. So lets configure this path. I am using windows vista. So i looks like this:(Tip: You must be logged as admin to change the environment variable)


Ok, now we need to add the JAVA_HOME to the systems PATH. The system path PATH is already in your list. Select it and click on edit. At the end of the file write that to it: %JAVA_HOME%\bin
You PC knows yet where the JDK is located and we are ready to go to the next step.

Downloading and installing JBoss AS7

go to: JBoss AS 7 and download JBoss for free. I will take the version jboss-as-7.1.1.Final.zip.

 
Note that Jboss does not have an installer. You simply unzip it in the directory you want. You may unzip it like this: C:\Software\JBoss. After that locate the folder called bin and start the command-console (cmd.exe) from here. We wanna test if the installed JBoss server works properly with our new installed JDK first, before we go on. Tip: To start the cmd.exe directly on you bin folder do that simple trick: Locate the bin folder of your JBoss installation, press and hold Shift, then perform with your mouse a right mouse click on the bin folder and select start command prompt from here. It could looks like this:


How to start JBoss?

Then type the new command standalone.bat and press enter in the cmd prompt.


This is the equivalent run.bat command in the older versions of JBoss. Per default JBoss will start with the default configurations like 64MB of heap as a minimum and 512MB as a maximum. Don't worry about it now. We will see how to change this later on this example. Open a browser of your choice now and type: http://localhost:8080 in it and hit enter. (that's the address of your installed JBoss server) you should see now the welcome page of JBoss AS7. Note: I don't know why, but if you type the server's address (http://localhost:8080) in Firefox for example and if you get an error like: This address is not valid or any other error. Close the tab and open a new tab and try it again first, before searching for installation errors. Try it on another browser as well. In my case, typing the server's address in firefox leads to an error. In Chrome it works just fine. After closing and opening a new tab in firebox it just works fine as well.

So we are done with the installation. Lets explore the new features from JBoss AS 7 from the command line before installing our IDE.

New Command Line Interface (CLI) with autocomplete function

locate the bin folder in your JBOSS_HOME (in my case it is C:\JBoss\jboss-as-7.1.1.Final\bin) and doble click the command jboss-cli.bat. you'll get a cmd-prompt like that bellow. type the command connect to connect to you running Jboss-Server.


This shell (command-prompt) is very smart and is able to autocomplete commands by hiting the key Tab when typing the first letters of a command. If you type for example the letter "s" and hit tab the shell will propose the command shutdown. That's very nice and confortable.

How can i stop JBoss?

To stop a running jboss server you can either type Ctrl+C or you can type the command :shutdown to issue an immediate stop.

How to stop Jboss over a script file?

If you wanna stop the server from a script file without the smart shell you can pass an option to the jboss-cli.bat command like this: jboss-cli.bat --connect command=:shutdown

How to stop a remote JBoss?

If you wanna stop a remote Jboss server to that on your Command Line Interface (CLI)
connect with the remote server typing its address. for example: connect 192.168.1.10
then execute the shutdown command like this: :shutdown

Installing Eclipse as an IDE (Integrated Development Environment)

Eclipse is currently an IDE that supports the most features for JBoss. It has a lot of useful plugins and extentions, it is also Java based and full compatible. go to: Eclipse here we will download the latest enterprise editon available.

Unzip the donwload eclipse file like Jboss in a directory of your choice. I recommend something like this: C:\eclipse. Locate in your ECLIPSE_HOME the folder eclipse (in my case it is: C:\eclipse\eclipse-jee-juno-SR1 because i've renamed the second eclipse folder to the downloaded file name) and double click the command eclipse.exe to start eclipse.


Eclipse will as you for a working place. This is nothing else then a folder of your choice in which your projects will be saved in. Attention: I recommend to place your workspace in your USER_HOME directory to avoid problems with your anti-virus program. In my case it is (C:\Users\Ricardo\ws_jboss)


How to install the Jboss tools on Eclipse

go to: Help > Install new software then hit the button add and type http://download.jboss.org/jbosstools/updates/development/juno/ in it. After that follow the screen sequences:


Making Jboss ready for Eclipse

Now you should be able to choose a new server by doing this: Ctrl+N and follow the screen sequences (Note: you may must specify your JBOSS_HOME directory in picture JBoss Runtime. In my case it was: C:\JBoss\jboss-as-7.1.1.Final):


Next post series coming soon... 

😱👇 PROMOTIONAL DISCOUNT: BOOKS AND IPODS PRO ðŸ˜±ðŸ‘‡

Be sure to read, it will change your life!
Show your work by Austin Kleonhttps://amzn.to/34NVmwx

This book is a must read - it will put you in another level! (Expert)
Agile Software Development, Principles, Patterns, and Practiceshttps://amzn.to/30WQSm2

Write cleaner code and stand out!
Clean Code - A Handbook of Agile Software Craftsmanship: https://amzn.to/33RvaSv

This book is very practical, straightforward and to the point! Worth every penny!
Kotlin for Android App Development (Developer's Library): https://amzn.to/33VZ6gp

Needless to say, these are top right?
Apple AirPods Pro: https://amzn.to/2GOICxy

😱👆 PROMOTIONAL DISCOUNT: BOOKS AND IPODS PRO ðŸ˜±ðŸ‘†