How to set up tomcat context path for web application? .war file name is coming infront of the application name in the url

I am having a trouble getting my web application ‘xyz’ running in tomcat 7 server hosted in DigitalOcean servers at:


The name of my .war file is “.MyWebApp”.

after deploying the .war file in tomcat, the application starts at:


any idea how to remove this “MyWebApp” part from the URL?

I have seen some of the solutions for this problem, they are mostly solutions of running the application in localhost. They suggested to change the ‘context.xml’ file which I already did like this:

<?xml version='1.0' encoding='utf-8'?>

    <!-- Default set of monitored resources -->

     path="" docBase="MyWebApp" debug="0" reloadable="true"

Any help would be very much appreciated!

Do not mark this as duplicate. I have checked all the solutions which worked for me in localhost, but not in digital ocean VPS. I think I am pretty specific here.

Thank you in advance!


I had to add this line in in the server.xml file. Tod do this:

nano etc/tomcat/server.xml

add this line:

 <Context path="" docBase="Advocatoree" debug="0" reloadable="true"></Context>

Save the file.

Restart tomcat.


SearchView in one activity, results in another one

My use case is the following: in activity A, I have an action bar with a collapsible SearchView. When the user gives her query and presses the ‘search’ button, I would like to show activity B with the results. I’m failing to do so, here is my code:


<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android=""

Activity A:

public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(, menu);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(;

    return true;

AndroidManifest for Activity A and B:



            <action android:name="android.intent.action.MAIN"/>

            <category android:name="android.intent.category.LAUNCHER"/>



    <activity android:name=".ActivityB">


            <action android:name="android.intent.action.SEARCH"/>




Howerver, no matter what I try, getSearchableInfo in A always returns null.

I have the feeling I’m not understanding something. The only way I can make getSearchableInfo() return not null is when I put the SEARCH intent filter and the searchable meta-data into activity A in the manifest. But then, when I press the ‘search’ button, another instance of activity A is started again on top of the current one, which definitely is not what I want. I guess I could add singleTop to A and handle the SEARCH action in onNewIntent and start B, but I generally don’t want A to be singleTop, I want the default. Or do I?

I tried adding this to A in the manifest (as suggested in some other threads):

        android:value=".ActivityB" >

What am I doing wrong?

EDIT: I replaced the ‘getComponentName()’ line in A with the following:

searchView.setSearchableInfo(searchManager.getSearchableInfo(new ComponentName(this, ActivityB.class)));

and it seems to work the way I want! Am I doing something wrong here, or is this the correct way? I’m a bit uncertain because it is not mentioned anywhere!


According to Android documentations, SearchManager.getSearchableInfo(componentName) takes one argument, which is:

componentName: The activity to get searchable information for

In your case you need ActivityB, so constructing a ComponentName that points to ActivityB is the correct way

new ComponentName(this, ActivityB.class)

Jersey MessageBodyWriter not found for media type=text/plain

I’m trying to follow the Jersey docs to enable a non-200 response if an error occured (

My code looks like :

public ResponseBuilder getData(@FormParam("one") String one,@FormParam("two") String two,@FormParam("three") String three) {
    if(one.isEmpty() || two.isEmpty() || three.isEmpty()) {
        logger.error("Missing params for getData");
        throw new WebApplicationException(501);
    return Response.ok();

This unfortunately yields the following error :

[2015-02-01T16:13:02.157+0000] [glassfish 4.1] [SEVERE] [] [org.glassfish.jersey.message.internal.WriterInterceptorExecutor] [tid: _ThreadID=27 _ThreadName=http-listener-1(2)] [timeMillis: 1422807182157] [levelValue: 1000] [[ MessageBodyWriter not found for media type=text/plain, type=class org.glassfish.jersey.message.internal.OutboundJaxrsResponse$Builder, genericType=class$ResponseBuilder.]]


The problem is the return type of your method. It has to be Response instead of ResponseBuilder.

Change your code to the following and it should work:

public Response getData(@FormParam("one") String one,@FormParam("two") String two,@FormParam("three") String three) {
    if(one.isEmpty() || two.isEmpty() || three.isEmpty()) {
        logger.error("Missing params for getData");
        throw new WebApplicationException(501);
    return Response.ok();

view.getViewTreeObserver().addOnGlobalLayoutListener leaks Fragment

When I use the GlobalLayoutListener to see if the softKeyboard is opened or not the fragment is not garbageCollected anymore after it is destroyed.

What I do:

  • I remove the Listener in the onDestroy() of my Fragment
  • I set the Listener to null in onDestroy()
  • I set the view that is observed to null in onDestroy()

Still leaks the fragment.

Does anyone had a similar issue and knows a fix for it??

My onDestroy:

public void onDestroy(){
    Log.d(TAG , "onDestroy");

    if(Build.VERSION.SDK_INT < 16){

    view = null;
    gLayoutListener = null;



I believe strongly removing the Listener, referenced by a View object, in onDestroy() is too late. This override method occurs after onDestroyView(), which supposed to “…clean up resources associated with its View.” You may use the same code in onStop() instead. Although I did not use this technique.

I can suggest this code, which I have used without any issues with the debugger.

// Code below is an example. Please change it to code that is more applicable to your app.
final View myView = rootView.findViewById(;
myView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
    @SuppressLint("NewApi") @SuppressWarnings("deprecation")
    public void onGlobalLayout() {

        // Obtain layout data from view...
        int w = myView.getWidth();
        int h = myView.getHeight();
        // ...etc.

        // Once data has been obtained, this listener is no longer needed, so remove it...
        else {


  • Since getViewTreeObserver is used for layouts, normally you need this listener for a short time only. Hence the listener is removed immediately.
  • The second call to removeOnGlobalLayoutListener() should be crossed out by the Studio since it is not available before JELLY_BEAN.
  • Pragma code @SuppressWarnings("deprecation") is not necessary if you’re using Android Studio.
  • Code myView = rootView.findViewById(; may need to change to a more applicable code to your app or situation.

getSupportFragmentManager().findFragmentById( started returning null

I have a map fragment inside another fragment. This was working before, but I think it messed up after I updated google play services library. What is wrong? fragment_map.xml:

    android:layout_height="match_parent" />


GoogleMap map;
private static View view;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    if (view != null) {
        ViewGroup parent = (ViewGroup) view.getParent();
        if (parent != null)
    try {

        view = inflater.inflate(R.layout.fragment_map, container, false);
        map = ((SupportMapFragment) getActivity()
                .getMap(); // NullPointerException at this line
    } catch (InflateException e) {
        /* map is already there, just return view as it is */

    return view;


I had to change




to get it working. No idea why it was working perfectly few days ago.

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..