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
# 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.
AuthName "Message Here"
AuthUserFile /path/to/password/file # Keep this outside of the web root.
Create the password file with the
htpasswd binary, and this should do the trick.