The authors develop a numerical procedure to analyze the adhesive contact between a soft elastic layer and an rough rigid substrate. The solution of the problem, which belongs to the class of the free boundary problems, is obtained by calculating the Green's function which links the pressure distribution to the normal displacements at the interface. The problem is then formulated in the form of a Fredholm integral equation of the first kind with a logarithmic kernel, and the boundaries of the contact area are calculated by requiring that the energy of the system is stationary. The methodology is relatively simple and easy to implement in a numerical code. The numerical scheme resulted to be very accurate in describing the singular character of the solution at the edges of the contact areas. This in particular is of utmost importance in order to calculate the energy per unit area required to move the edges of the contact regions and to determine the exact extension of the contacts. The numerical scheme has been used to analyze the adhesive properties of a confined layer in contact with a wavy rigid substrate as a function of thickness, applied stress or penetration. It is shown that reducing the thickness of the slab reduces the effective energy of adhesion, i.e. the work needed to separate the bodies, but nevertheless increases the adherence force between the slab and the substrate. However, thinning the slab also increases the confinement of the system and therefore increases the negative hydrostatic pressure in the layer. This, in turn, may produce cavitation. When this happens the rupture of the adhesive bond does not occur through interfacial crack propagation but, by the growth of new interfacial voids or cavities.