Reputation: 11
I have a weird problem with java - I am programming in Intellij Idea, I am using this little code to make basic authorization to site
String authString = name + ":" + password;
byte[] binaryData = authString.getBytes();
String authStringEnc = new String(Base64.encodeBase64(binaryData));
URL url = new URL(webPage);
URLConnection urlConnection = url.openConnection();
urlConnection.setRequestProperty("Authorization", "Basic " + authStringEnc);
InputStream is_auth = urlConnection.getInputStream();
InputStreamReader isr = new InputStreamReader(is_auth);
This code worked for some weeks, but I continued writing my program. Then yesterday I saw that - program works when I click run in Intellij, but when I start a .jar file, this line cannot be done:
String authStringEnc = new String(Base64.encodeBase64(binaryData));
I don't know why, but program stops when doing this line. But when I click run or debug in Intellij, everything is working.
Btw. I am using this library for encodeBase64:
import org.apache.commons.codec.binary.Base64;
If you don't know why it isn't working, maybe you can share with me idea to make a basic authorization to site. Thanks in advance.
Upvotes: 1
Views: 940
Reputation: 11
The answer is: I only had to refresh jar artifact. I deleted old artifact and created it again, after this everything is working well.
Upvotes: 0
Reputation: 3931
You need to add the Apache Commons Codec jar to your classpath when you run the jar file. You should make sure that any other jar files/libraries that you have added in IntelliJ are also on the classpath.
Upvotes: 2
Reputation: 877
You should use logging in order to research your stacktrace. Probably you have some ClassNotFound exception or something similarly obvious.
Upvotes: 0