Hamiltonian classical electrodynamics

After coming across the Lagrangian density of the Maxwell equations $$\mathcal{L} = -\frac{1}{4\mu_0} F_{\mu\nu}F^{\mu\nu}-J_\mu A^\mu = \frac{\varepsilon_0}{2}||\mathbf{E}||^2-\frac{1}{2\mu_0}||\mathbf{B}||^2 -j_\mu A^\mu$$ I was wondering whether there is a corresponding Hamiltonian for Classical Electrodynamics. I have found that for the source-free case ($$j_\mu$$=0) it is $$\mathcal{H}=\frac{\varepsilon_0}{2}||\mathbf{E}||^2+\frac{1}{2\mu_0}||\mathbf{B}||^2,$$ yet I have only seen it in a couple of places and never including the source terms.

Is there any Hamiltonian that works with sources as well? If not, what could be the reason?

PS: there seems to be a similar question Is there a Hamiltonian for the (classical) electromagnetic field? If so, how can it be derived from the Lagrangian? but no Hamiltonian is given in the answers...

• As the answer to the linked question suggests...have you tried just performing the Legendre transform yourself? If $J$ is just a background current, this should be straightforward as far as I can recall. Commented Apr 13, 2021 at 22:11

$$\mathcal{H} = \frac{\varepsilon_0}{2}\mathbf{E}^2 + \frac{1}{2\mu_0}\mathbf{B}^2 - j_\mu A^\mu$$ and $$\nabla\cdot\mathbf{E}=\frac{\rho}{\varepsilon_0}$$