An example configuration in Apache, since you mentioned it in your question.. but any ol' web server software (nginx, lighttpd) should work - let me know if you would prefer one of the others.
Say you've switched the java application to listen on 127.0.0.1:8000
.
# I'm making this a port 443 example because basic authentication
# is completely unencrypted - if the credentials are sensitive at all,
# you should be using SSL. Change the port and drop the SSL directives if needed.
<VirtualHost *:443>
ServerName example.com
SSLEngine On
SSLCertificateFile /path/to/public.pem
SSLCertificateKeyFile /path/to/private.key
<Location />
AuthType Basic
AuthName "Message Here"
AuthBasicProvider file
AuthUserFile /path/to/password/file # Keep this outside of the web root.
Require valid-user
ProxyPass http://127.0.0.1:8000/
ProxyPassReverse http://127.0.0.1:8000/
</Location>
</VirtualHost>
Create the password file with the htpasswd
binary, and this should do the trick.