I am developing a Fabric Minecraft mod that will send http requests.
Here is the code I used:
import com.google.gson.JsonObject;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import java.io.IOException;
public class NetworkUtils {
public static void post(String url, JsonObject json) throws IOException {
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
HttpPost request = new HttpPost(url);
StringEntity params = new StringEntity(json.toString());
request.addHeader("content-type", "application/json");
request.setEntity(params);
httpClient.execute(request);
httpClient.close();
}
}
It worked well when I run it in the development environment. However, when I build it into a jar file and put it in the mods
folder of an actual server, it produce the following error:
java.lang.NoClassDefFoundError: org/apache/http/HttpEntity
How can I fix it? Thank you so much if you can help