I am trying my own way of deriving the Hamilton Jacobi equation
$$\frac{\partial S}{\partial t} = -H \tag{1}$$
through direct variation. I think the difficulty of doing this is that the upper limit of integral:
$S = \int_0^t L dt$
is actually varying. So I try to rewrite the integral in an alternative form:
$S = \int_0^1 L(q(z),\dot{q}(z)) \frac{\partial t}{\partial z} dz$.
Here $z$ parameterize the 'progress' of the motion from the start to the end, which is alway from 0 to 1. Then:
$\delta S = \int_0^1 \{(\frac{\partial L}{\partial q}\delta q+\frac{\partial L}{\partial \dot{q}}\delta \dot{q}) \frac{\partial t}{\partial z}+L\frac{\partial \delta t}{\partial z}\} dz$.
Consider the first two terms first:
$\int_0^1 (\frac{\partial L}{\partial q}\delta q+\frac{\partial L}{\partial \dot{q}}\delta \dot{q}) \frac{\partial t}{\partial z}dz$
By the euler lagrange equation (it holds because we are considering a real trajectory) , also replace time derivative by $\frac{dz}{dt}\frac{d}{dz}$ the first term could be written as:
$=\int_0^1 (\frac{dz}{dt}\frac{d}{dz}\frac{\partial L}{\partial \dot{q}}\delta q+\frac{\partial L}{\partial \dot{q}}\frac{dz}{dt}\frac{d}{dz}\delta q) \frac{\partial t}{\partial z}dz$
$=\int_0^1 (\frac{d}{dz}\frac{\partial L}{\partial \dot{q}}\delta q+\frac{\partial L}{\partial \dot{q}}\frac{d}{dz}\delta q) dz$
Integrate the second term by parts:
$=\int_0^1 (\frac{d}{dz}\frac{\partial L}{\partial \dot{q}}\delta q-\frac{d}{dz}\frac{\partial L}{\partial \dot{q}}\delta q) dz=0$
The boundary term vanishes because $\delta q$ vanish at the start and the end (we are only varying the arrival time). Now consider the second part:
$\int_0^1 L\frac{\partial \delta t}{\partial z} dz$.
integration by part again:
$=L \delta t|^{z=1}_{z=0} - \int_0^1 \frac{\partial }{\partial z} L \delta tdz$.
$=L \delta t|^{z=1}_{z=0} - \int_0^1 (\frac{\partial L}{\partial q}\frac{dq}{dz}+\frac{\partial L}{\partial \dot{q}}\frac{d\dot{q}}{dz})\delta t dz$.
$=L \delta t|^{z=1}_{z=0} - \int_0^1 (\frac{dz}{dt}\frac{d}{dz}\frac{\partial L}{\partial \dot{q}}\frac{dq}{dz}+\frac{\partial L}{\partial \dot{q}}\frac{d\dot{q}}{dz})\delta t dz$.
$=L \delta t|^{z=1}_{z=0} - \int_0^1 (\frac{d}{dz}\frac{\partial L}{\partial \dot{q}}\dot{q}+\frac{\partial L}{\partial \dot{q}}\frac{d\dot{q}}{dz})\delta t dz$.
$=L \delta t|^{z=1}_{z=0} - \int_0^1 (\frac{d}{dz}(\frac{\partial L}{\partial \dot{q}}\dot{q})\delta t dz$.
$=L \delta t|^{z=1}_{z=0} - (\frac{\partial L}{\partial \dot{q}}\dot{q})\delta t |_{z=0}^{z=1}+\int_0^1 \frac{\partial L}{\partial \dot{q}}\dot{q}\frac{d}{dz}\delta t dz$.
The first two terms is just what I need ($-H\delta t|_{z=0}^{z=1}$). However, the last term also shows up, which does not seem to be zero.
Is this approach to derive H-J equation viable? If not, where did I make the mistake?