Fwd: APK build but Jetty does not run in Android

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Fwd: APK build but Jetty does not run in Android

jack daniel

I am trying to embed 9.0.0.v20130308 in Android (the latest Jetty in android, returns a dex error). But it is not working.

I am trying to make Jetty listen to a custom incoming HTTP method, NOTIFY. It works in desktop, now I am trying to import it to Andoird

Here is my code.

package com.example.arjun.hellotest;

import android.util.Log;

import java.io.IOException;
import java.io.BufferedReader;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AbstractHandler;

import org.eclipse.jetty.server.HttpConnectionFactory;

public class HelloWorld extends AbstractHandler
public void handle( String target,
Request baseRequest,
HttpServletRequest request,
HttpServletResponse response ) throws IOException,
// Declare response encoding and types
// implementation files('libs/jetty-all-uber.jar')
response.setContentType("text/html; charset=utf-8");

// Declare response status code

// Write back response
response.getWriter().println("<h1>Hello World</h1>");

// Inform jetty that this request has now been handled

String requestMethod = baseRequest.getMethod().toUpperCase();

StringBuffer jb = new StringBuffer();
String line = null;

Map<String, String> map = new HashMap<String, String>();

try {

switch (requestMethod) {

case "POST":
// do post logic
Log.w("JettyTest", "Handle POST request");

case "NOTIFY":
// do notify logic
Log.w("JettyTest", "Handle NOTIFY request");

Enumeration headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) {
String key = (String) headerNames.nextElement();
String value = request.getHeader(key);
map.put(key, value);


for (String key : map.keySet()) {
Log.w("JettyTest", key + ": " + map.get(key));

Log.w("JettyTest", "Remote: "+request.getRemoteHost()+":"+request.getRemotePort());

BufferedReader reader = request.getReader();
while ((line = reader.readLine()) != null)

Log.w("JettyTest", jb.toString());

case "GET":
// do get logic
Log.w("JettyTest", "Handle GET request");

// so on.....

// do default
Log.w("JettyTest", "NOT IMPLEMENTED");


} catch (Exception e) {

public static void main( String[] args ) throws Exception
//Server server = new Server(8080);
//server.setHandler(new HelloWorld());

Runnable runnable = new Runnable() {
public void run() {
Server server = new Server(8082);
try {
server.setHandler(new HelloWorld());

Log.w("JettyTest", "Server Started");
} catch (Exception e) {
new Thread(runnable).start();


Build.gradle file

apply plugin: 'com.android.application'

android {
compileSdkVersion 26
defaultConfig {
multiDexEnabled true
applicationId "com.example.arjun.hellotest"
minSdkVersion 22
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
repositories {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'org.eclipse.jetty:jetty-webapp:9.0.0.v20130308'


In AndroidManifest

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />


It builds the APK. I was able to install it in Android 6.0(Redmi4a). But nothing happens. I can't confirm if the server started. There is no log entry in adb.

What am I doing wrong. What is the correct way to make Jetty server run in Android?

Please help.

jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit