Work done by a variable force is:
\[
W=\int_{x_1}^{x_2} F\,dx
\]
Here,
\[
F=3x^2
\]
So,
\[
W=\int_0^2 3x^2\,dx
\]
\[
W=3\int_0^2 x^2\,dx
\]
\[
W=3\left[\frac{x^3}{3}\right]_0^2
\]
\[
W=\left[x^3\right]_0^2
\]
\[
W=2^3-0=8
\]
So the work done is:
\[
\boxed{8\text{ J}}
\]
Hence, the correct answer is:
\[
\boxed{(D)}
\]