Hamiltonian Constraints, the Jacobi Principle and Gravity