lundi 22 juillet 2013

There are no resources that can be added or removed from the server

Some time would like to deploy an ear file to WAS (Web Application Server) as usual. But Eclipse fail to find your EAR and it show an alert like this :

 There are no resources that can be added or removed from the server   

the solution is that your project needs to have a Eclipse Dynamic Web Module facet. 

  1. right click on project and click properties
  2. Go to Project Facet and Select dynamic web module and click apply.
  3. go to tomcat and click add/remove

How to fix GC overhead limit exceeded in Eclipse


Eclipse will throw GC overhead limit exceeded error when it runs out of memory, normally while performing memory-consuming operations such as building workspace on big projects.

 An internal error occurred during: "Building workspace". GC overhead limit exceeded  
To fix this problem, you'll need to allocate more memory to your Eclipse instance. To do this, go to the Eclipse installation directory, and locate the eclipse.ini file.
To increase the memory allocation for your Eclipse instance, edit the number in the following lines accordingly.
 -Xms1024m   
 -Xmx2048m  
The number is the amount of memory, in Megabytes.
You can also increase the value of MaxPermSize, as the following:
 -XX:MaxPermSize=1024m  

Restart Eclipse for the changes to take effect.

lundi 8 juillet 2013

Comment afficher une Valeur double avec 2 chiffres aprés la Virgule ?


La classe java.text.DecimalFormat permet de formater une valeur numérique dans le format de son choix en utilisant un pattern dont les symboles principaux sont les suivants :
  • 0 permet de représenter un chiffre qui devra obligatoirement être présent, même s'il s'agit d'un zéro inutile.
  • # permet de représenter un chiffre en ignorant les zéros inutiles.
  • . (le point) permet de représenter le séparateur de la partie décimale.
  • , (la virgule) permet de représenter le séparateur des groupes (milliers, millions, etc.).

(vous pouvez vous reporter à la documentation de la classe DecimalFormat pour obtenir la liste complète de tous les symboles).
Format 0 0,02 0,8 12,9
# 0 0 1 13
### 0 0 1 13
0 0 0 1 13
000 000 000 001 013
#.## 0 0,02 0,8 12,9
0.## 0 0,02 0,8 12,9
0.00 0,00 0,02 0,80 12,90
#.00 ,00 ,02 ,80 12,90
#,##0.00 0,00 0,02 0,80 12,90

par exemple :
double ma_Valeur ;
DecimalFormat df = new DecimalFormat("#.##");
System.out.println(df.format(ma_Valeur));

mercredi 3 juillet 2013

Restore Deleted Files using Git


Sometime you can delete a file  ,by accident, and then you commit your changes . after a while you recognize that you need this file So what you can do ??
what I have tried to resolve such problem (there are several ways) is  this few steps :
  1. List all files that have been deleted from my git repository :
    git log --diff-filter=D --summary
    
    
  2. Search the commit where you deleted your file
  3. undo your commit to the searched one BUT don't lose your modifications by taping this cmd :
    git reset --soft HEAD~n   
    

    n: is the number of undo commit steps

  4. if you type  git status  you will re-view your deleted file so to get the file back type this cmd :
    git checkout -- [file name]
    
Hope this could helps someone :D

samedi 29 juin 2013

Change Wicket component behavior

Behaviors are kind of plug-ins for Components. They allow functionality to be added to a component and get essential events forwarded by the component. They can be bound to a concrete component (using the bind method which is called when the behavior is attached), but they don't need to. They can modify the components markup by changing the rendered ComponentTag. These are some of them : 
  1. AbstractAjaxTimerBehavior

  2. A behavior that generates an AJAX update callback at a regular interval. java doc

    WicketComponenet.add(new AbstractAjaxTimerBehavior(Duration.milliseconds(300)){
    @Override
    protected void onTimer(AjaxRequestTarget target) {
    // TODO Auto-generated method stub
    System.out.println("ajax here!");
    target.add(ComponentToModify);
    }});
    



  3. AjaxEventBehavior

  4. An ajax behavior that is attached to a certain client-side (usually javascript) event, such as onClick, onChange, onKeyDown, etc. Example:
    WebMarkupContainer div=new WebMarkupContainer(...);
             div.setOutputMarkupId(true);
             div.add(new AjaxEventBehavior("onclick") {
                 protected void onEvent(AjaxRequestTarget target) {
                     System.out.println("ajax here!");
                 }
             }
    
    This behavior will be linked to the onclick javascript event of the div WebMarkupContainer represents, and so anytime a user clicks this div the onEvent(AjaxRequestTarget) of the behavior is invoked. Java doc

  5. AjaxFormComponentUpdatingBehavior

  6. If you have a form component in wicket with some components and you want to change using ajax some things in that form before submit (when you click or edit on one of the components), then you have to use AjaxFormComponentUpdatingBehavior. This is a behavior that updates the hosting FormComponent via ajax when an event it is attached to is triggered.

    WicketComponenet.add(new AjaxFormComponentUpdatingBehavior("onchange"){ 
    @Override
    protected void onUpdate(AjaxRequestTarget target){
    // TODO 
    System.out.println("ajax here!"); 
    target.add(ComponentToModify);
    }}.setThrottleDelay(Duration.seconds(1))
    );
    ComponentToModify.setOutputMarkupId( true );
    

    The key is that your component must be a FormComponent, otherwise the event won't be triggered. Simple components like CheckBox, TextField, DropDownChoice are all FormComponents. Java Doc
    you should be careful to set setOutputMarkupId(true) of the component that will be modified after defining the behavior !

mercredi 26 juin 2013

Jenkins getting Started


Jenkins Overview

Jenkins Continuous Integration (CI)

server was created to manage and control development lifecycle processes of all kinds, including build, document, test, package, static analysis and many more. Jenkins supports two main functions to help you improve code quality:

Ongoing building and testing

an easy-to-use continuous integration system, Jenkins lets you easily integrate changes to a software project and then automatically initiate a fresh build. By integrating changes as soon as they're ready, you'll find problems sooner, reduce integration conflicts and ensure you always have a working build.

Monitoring the execution of externally-run jobs

Jenkins schedules, monitors and manages externally-run jobs as well, such as cron jobs and procmail jobs and can even handle operations on a remote machine. The tool immediately informs you if something goes wrong, so you can fix the problem right away.

Built-in Automatic Backup

Jenkins lets you define regular backup schedules and control what to back up. Backups can be pushed to a remote server via SFTP or to a local file system. In this way, you configuration will be protected even in case of disaster like disk failures.

Self-upgrade

Upgrading Jenkins to a newer version is really easy. If you choose the native package (such as .deb or .rpm), your package manager will update it automatically. If you choose other installation methods, Jenkins will update itself with a click of a button from GUI.

Jenkins Jobs

in the table you find the list of existant jobs.

Create New Job

you have just to click to new job in the left and the folowing screen will appear.

next give a small description to your job :

Build New Job

After creating your job you can start your build by clicking on Start Build :

Job Configuration

The created jobs must be configured as follow :

Git Configuration

to use Jenkins you have to use a system version Control like Git or svn. If you are using an Http protocol to manage remote repository you need to specify the user credentials in the URL :
http://username:password@ci.opuntia360.com/....

Cron Configuration

the automation build is managed by the peridic Build option. This field follows the syntax of cron (with minor differences). Each line consists of 5 fields separated by TABs or spaces:
MINUTES HOURS JOURMOIS MONTH JOURSEMAINE
MINUTES The minutes in an hour (0-59)
HOURS The hours in a day (0-23)
JOURMOIS the day in a month (1-31)
MONTH The month (1-12)
JOURSEMAINE The day of the week (0-7) where 0 and 7 are Sunday
for example I have so far used Periodic build in jenkins where the schedule:
*/2 * * * * builds the project every 2 minutes


Email Notification

Jenkins offer to you the oportunity to make a post build task.one of the import tasks is mail notification.

Smtp Config

it is very import to configure jenkins to know you smtp server.

Send Email After Build

click to create a post build step and choose "Editable Email Notification" and specify your mail adress.

UBUNTU: HOW TO CHANGE THE COMPUTER NAME (HOSTNAME)




Change Your Computer Name (Ubuntu)
You might run into a situation that requires you to change your (hostname) computer name, either because you need it to meet a naming scheme or you’re just bored with it and want something better. By following these steps, you’ll give your computer a new identity in no time.
  1. To get started, press Ctrl – Alt – T on your keyboard to open the Terminal. Next, type the command below to open the hostname file.
  2. Type this commande into the terminal and remember that the current computer name is @aymen-Aspire-E1-571


gksu gedit /etc/hostname
3.   Then change the name to whatever you like and save the file.

4. Next, while command console is still open, type the command below to open the hosts file.
gksu gedit /etc/hosts

5. Finally, change the name shown to complete the change and save the file.

6. Close all open windows and restart your system.
After your system has restarted, it will have the new computer name.