Doubt regarding Ampere's Circuital Law The Ampere's Circuital law states
$$\oint B\cdot d\ell~=~ \mu_0I$$
We can use it to derive the magnetic field of an infinitely long current carrying wire easily. My question is, why does the wire need  to be infinitely long?
I know it has something to do with $B$ being constant and tangential to the loop at every point for easy evaluation of the integral, but I can't find an explanation to my question.
 A: We use the idealized case of an infinitely long current to be able to justify (by symmetry) that the strength of the field will only depend on the radial coordinate $r$, so that it can be taken out of the integral, since we are only integrating over the angle which parametrizes a circle around the wire:
$$ \oint B\cdot d\ell
= B \int_0^{2\pi}r\ d\theta = 2\pi r B = \mu_0 I\implies B=\frac{\mu_0I}{2\pi r}$$
If the wire is not infinitely long, you can move towards the end of it, where it is obvious that the $B$-field should not just depend on the radial coordinate, so our simple calculation fails. In practice, one can very often use this ideal case as a good approximation for the field close to the wire - so long as the distance from the wire is much smaller than the length of the wire the effect is pretty much that of an infinite wire.
A: First of all, I would suggest you to read the comments I have made in the Danu's answer to check whether I have understood your question or not.
See,
$\oint B\cdot d\ell~=~ \mu_0I$ has been derived only on the basis of $\vec{\nabla}\times \vec{B}=\mu_0 \vec{J}$. But actually the Maxwell equation is $\vec{\nabla}\times \vec{B}=\mu_0 (\vec{J}+\epsilon_0 \frac{\partial \vec{E}}{\partial t})$ which is consistent with the continuity eqution. 
Now in the case of infinite wire $\vec{\nabla}\times \vec{B}=\mu_0 \vec{J}$ is sufficient as at the region of interest $\vec{\nabla} \cdot \vec{J}=0$.
But in the case of finite wire alone there is accumulation of charge in the finite wire so that $\vec{\nabla} \cdot \vec{J}+ \frac{\partial \rho}{\partial t}=0$. So relevant Maxwell equation is $\vec{\nabla}\times \vec{B}=\mu_0 (\vec{J}+\epsilon_0 \frac{\partial \vec{E}}{\partial t})$ . See the Ampere's law in this case is given by this, not by the $\oint B\cdot d\ell~=~ \mu_0I$. So you are applying wrong formula and that is why you are getting wrong answer.
