We study a statistical model describing the steady-state distribution of the fluxes in a metabolic network. The resulting model defined on continuous variables can be solved by the cavity method. In particular, analytical tractability is possible, solving the cavity equation over an ensemble of networks with the same degree distribution as a real metabolic network. The flux distribution that optimizes production of biomass has a fat tail with a power-law exponent independent of the structural properties of the underlying network. These results are in complete agreement with the flux-balance-analysis outcome and in qualitative agreement with the experimental results.