Tomcat:java.net.ConnectException:拒绝连接

时间:2015-10-31 07:02:18

标签: java tomcat

我在上传新的war文件后试图关闭并启动我的tomcat。但我在关闭tomcat实例时遇到连接拒绝错误。错误如下,

Oct 31, 2015 2:55:44 AM org.apache.catalina.startup.Catalina stopServer
SEVERE: Could not contact localhost:8005. Tomcat may not be running.
Oct 31, 2015 2:55:44 AM org.apache.catalina.startup.Catalina stopServer
SEVERE: Catalina.stop:
java.net.ConnectException: Connection refused
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
        at java.net.Socket.connect(Socket.java:589)
        at java.net.Socket.connect(Socket.java:538)
        at java.net.Socket.<init>(Socket.java:434)
        at java.net.Socket.<init>(Socket.java:211)
        at org.apache.catalina.startup.Catalina.stopServer(Catalina.java:498)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.apache.catalina.startup.Bootstrap.stopServer(Bootstrap.java:370)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:457)

Tomcat stopped

即使我使用kill -9 PID杀死了运行java id,但我仍然遇到同样的错误,我无法启动我的应用程序。

如何修复此问题并在没有错误的情况下关闭我的tomcat?

3 个答案:

答案 0 :(得分:1)

如果它的窗口尝试下面杀死正在运行的tomcat进程

public class Main_Page extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {

@Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main__page);

    // Left DraweLayout Open
        Drawer = (DrawerLayout) findViewById(R.id.DrawerLayout);
        mNaviView = (NavigationView) findViewById(R.id.main_drawer);
        mNaviView2 = (NavigationView) findViewById(R.id.main_drawer2);
        mNaviView.setNavigationItemSelectedListener(this);
        mDrawerToggle = new ActionBarDrawerToggle(this, Drawer, toolbar, R.string.openDrawer, R.string.closeDrawer) {

            @Override
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
                if (con.isOnline()) {
                    new get_menu_info().execute(public_username);
                }
            }

            @Override
            public void onDrawerClosed(View drawerView) {
                super.onDrawerClosed(drawerView);

            }
        };
        Drawer.setDrawerListener(mDrawerToggle);
        mDrawerToggle.syncState();

    // Right DraweLayout Open
        ImageView profile_menu = (ImageView) toolbar.findViewById(R.id.right_tool);
        profile_menu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Drawer.openDrawer(mNaviView2);
            }
        });
}

  @Override
    public boolean onNavigationItemSelected(MenuItem menuItem) {
        Intent intent;

        if (menuItem.getItemId() == R.id.menu_action_mySMS) {
            intent = new Intent(this, MySMS_Page.class);
            startActivity(intent);
            overridePendingTransition(R.anim.abc_slide_in_bottom, R.anim.abc_slide_out_top);
            finish();
            return true;
        }

        if (menuItem.getItemId() == R.id.menu_profile_action_favorite) {
            intent = new Intent(this, Fav_Page.class);
            startActivity(intent);
            overridePendingTransition(R.anim.abc_slide_in_bottom, R.anim.abc_slide_out_top);
            finish();
            return true;
        }

        if (menuItem.getItemId() == R.id.menu_action_category) {
            intent = new Intent(this, category_Page.class);
            startActivity(intent);
            overridePendingTransition(R.anim.abc_fade_in, R.anim.abc_fade_out);
            finish();
            return true;
        }

        if (menuItem.getItemId() == R.id.menu_action_setting) {
            intent = new Intent(this, setting_Page.class);
            startActivity(intent);
            overridePendingTransition(R.anim.abc_fade_in, R.anim.abc_fade_out);
            finish();
            return true;
        }

        if (menuItem.getItemId() == R.id.menu_action_about) {
            intent = new Intent(this, about_Page.class);
            startActivity(intent);
            overridePendingTransition(R.anim.abc_fade_in, R.anim.abc_fade_out);
            finish();
            return true;
        }

        if (menuItem.getItemId() == R.id.menu_action_top) {
            intent = new Intent(this, top_Page.class);
            startActivity(intent);
            overridePendingTransition(R.anim.abc_fade_in, R.anim.abc_fade_out);
            return true;
        }

        if (menuItem.getItemId() == R.id.menu_action_free_com) {
            intent = new Intent(this, freeCon_Page.class);
            startActivity(intent);
            overridePendingTransition(R.anim.abc_fade_in, R.anim.abc_fade_out);
            return true;
        }
        return false;
    }
}

在Linux中如果C:\Users\Saravana.Saravana-PC>netstat -ano | find ":8080" TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 1448 TCP 127.0.0.1:8080 127.0.0.1:49543 ESTABLISHED 1448 TCP 127.0.0.1:49543 127.0.0.1:8080 ESTABLISHED 4068 TCP [::]:8080 [::]:0 LISTENING 1448 TCP [::1]:8080 [::1]:49542 ESTABLISHED 1448 TCP [::1]:49542 [::1]:8080 ESTABLISHED 4068 C:\Users\Saravana.Saravana-PC>taskkill.exe /PID 1448 /F SUCCESS: The process with PID 1448 has been terminated. C:\Users\Saravana.Saravana-PC> 没有停止tomcat那么

stopTomcat.sh

杀死正在运行的tomcat实例,查杀你的java应用程序不会杀死tomcat

要使正在运行的tomcat端口使用ps -ef | grep "tomcat" kill -9 <PID>

答案 1 :(得分:0)

我清理了我的webapps并帮助了我:

cd /opt/tomcat/webapps
shopt -s extglob
rm -rf !(ROOT|balancer|webdav)
之后,我能够部署我的应用程序

答案 2 :(得分:-1)

尝试将端口号从8005更改为其他端口号,然后重新启动Eclipse。

有时可能会发生端口号被突然终止进程阻止