Tag Archives: tomcat

[Solved] nacos Startup Error: Unable to start embedded Tomcat

Project scenario:

Nacos is prepared to be used as the configuration center. Version 1.3.1 (official recommended stable version – January 11, 2021)
MySQL version: version 5.7 (I heard that version 5.8 has changed greatly), otherwise nacos-mysql.sql file cannot be run
JDK version: 1.8.0_144 (the lower version not works)


Problem Description:

1. Run the spring cloud Alibaba Nacos source code in the local idea, and an error is reported: unable to start embedded Tomcat

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:157)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:540)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
	at com.alibaba.nacos.Nacos.main(Nacos.java:35)
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
	at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:125)
	at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:86)
	at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:414)
	at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:174)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:181)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:154)
	... 8 common frames omitted

Cause analysis:

Modified in the application.properties configuration file as below:

#*************** Config Module Related Configurations ***************#
### If use MySQL as datasource:
spring.datasource.platform=mysql

### Count of DB:
db.num=1

### Connect URL of DB:
db.url.0=jdbc:mysql://127.0.0.1:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user=root
db.password=root

Solution:

The solution of idea
The source code was downloaded locally and imported into idea, no error was reported or anything (although the import will prompt that various classes cannot be found or something) The startup class is in the console module, you need to modify the application.properties of this module, the modification method is the same as the modification method of the configuration file of nacos server, Nacos local source code build Start, if not a cluster start, you need to add -Dnacos.standalone=true in the start parameters.
1. Click Edit Configurations in the upper right corner

2. In the pop-up interface, enter -Dnacos.standalone=true in VM options, save it

[Solved] Tomcat startup error: sub-container startup failed

Tomcat Startup Error:

When reviewing Java Web, I want to make my workspace cleaner, so I cleaned up the web projects left in the Tomcat installation directory webapps, and double-click start Bat file, the CMD window flashes by, and I feel strange at once. This situation is usually JAVA_Home environment variable is not configured correctly.


Then open start.bat in text mode, add “pause” after the end statement at the end, and double-click start.bat again after saving, the following results appear:

It is found that the paths are correct, indicating that there is no problem with my environment variable configuration.


Open start.bat again as text, call call "%EXECUTABLE%" start %CMD_LINE_ARGS% statement is changed to run. After saving, double-click start.bat, the following message appears:

A series of errors are shown later, and I only cut one illustratively.

The main information observed is that the sub-container failed to start, and a specified resource set is invalid. The service component necessary Catalina.start fails to start; When you look carefully, you find that it shows an invalid resource set path (at the end of the figure above). You can see that there is no relevant folder under this path.

So I looked at the server.xml file in the conf directory and saw the following configuration (only the code was intercepted):

<Service name="Catalina">
    <Engine defaultHost="localhost" name="Catalina">
        <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
            <Context docBase="E:apache-tomcat-9.0.20webappsSSM" path="/SSM" reloadable="true" source="org.eclipse.jst.jee.server:SSM"/>
            <Context docBase="E:apache-tomcat-9.0.20webappsSpring" path="/Spring" reloadable="true" source="org.eclipse.jst.jee.server:Spring"/>
            <Context docBase="E:apache-tomcat-9.0.20webappsPressRelease" path="/PressRelease" reloadable="true" source="org.eclipse.jst.jee.server:PressRelease"/>
        </Host>
    </Engine>
</Service>

In the Context tag, docBase specifies the path of the project, which is accessed through the virtual path path. Because I deleted these three folders together when cleaning the project before, there was an error when Tomcat started.

Delete the contents of the three Context tags in the server.xml file, double-click start.bat after saving, and find that Tomcat has started normally and can access port 8080;

Or create the corresponding SSM, Spring, and PressRelease folders in the webapps directory, and Tomcat can also be started normally.

[Solved] Tomcat Error: Failed to start componen

I make a crud project of servlet + JSP, and start Tomcat with an error:

org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/oa3]]

It was found that the path was not added ‘/’

//@WebServlet("dept/list")
//Add slash!
@WebServlet("/dept/list")
public class DeptServlet extends HttpServlet {

 

[Solved] Nacos1.3.2 Startup Error: Unable to start embedded Tomcat

Recently, I started to plan to learn springcloud-alibaba, so I downloaded the Nacos installation package on the GitHub official website, and found an error on startup.

Error message: Unable to start embedded Tomcat
the built-in Tomcat cannot be loaded.

Opened the conf folder and saw a nacos-mysql.sql
It seems to import a database script, so I created a database named nacos in the local database
and executed this sql script, which generated some tables.

With a database and tables, we must change the configuration.
So I opened application.properties with an editor
I saw that there is a place to configure the db, so I changed it.

After saving
enter the bin directory again and double-click startbat.cmd to start.

I found that I still reported an error.


Caused by: java.net.UnknownHostException: jmenv.tbsite.net

Here I have changed the configuration file again, but it has no effect.

The key point is that during startup, I noticed a message,
Nacos has been started in cluster mode. Cluster list is []

I wonder if this is the problem, because I clicked run and did not configure the Nacos cluster.

So I use the editor to open the startup.cmd in the dictory bin
see a key message

Here you can configure click mode startup, so try to change the startup configuration to click mode startup

Exit after saving. Double click the startup file startup.cmd

It started normally this time.

Enter in Browser: localhost:8848/nacos/index.html

Normally access the Nacos configuration center.

[Solved] Docker Run Tomcat Error: Cannot find /usr/local/tomcat/bin/setclasspath.sh

Docker reports an error when running Tomcat

Cannot find /usr/local/tomcat/bin/setclasspath.sh
This file is needed to run this program

After trying, use the add command packaged with dockerfile

RUN unset CATALINA_HOME

Invalid after attempt

The prompt is that setclasspath.sh cannot be found, because this Tomcat restarts repeatedly

So use the command to copy a bin directory to the current folder

docker cp Docker_id:/usr/local/tomcat/bin ./

The result shows that setclasspath.sh exists, so where is the problem? Look for the error reporting code

In the catalina.sh script, the part causing the problem is as follows:


  if [ -r "$CATALINA_HOME"/bin/setclasspath.sh ]; then
    . "$CATALINA_HOME"/bin/setclasspath.sh
  else
    echo "Cannot find $CATALINA_HOME/bin/setclasspath.sh"
    echo "This file is needed to run this program"
  fi

The square brackets plus the -r command means to test whether the file is read-only. Similarly, – x tests whether the file is executable

In the problematic system, the – R command call in the container is abnormal.

Try to start a temporary tomcat8 authentication,

docker run -it --rm --entrypoint=/bin/bash tomcat:8

Note: executing the docker run command with the –rm command option is equivalent to executing docker rm -v after the container exits
execute command

root@f338debf92f6:/usr/local/tomcat# [[ -r /bin/bash ]]
root@f338debf92f6:/usr/local/tomcat# echo $?
1

Executed on a normal system

root@0083a80a9ec2:/usr/local/tomcat# [[ -r /bin/bash ]]
root@0083a80a9ec2:/usr/local/tomcat# echo $?
0

The command ‘$?’ indicates the exit status of the previous command or the return value of the function
for exit status, 0 indicates no error, and any other value indicates an error. In general, most commands return 0 upon successful execution and 1 upon failure. Some commands return other values, indicating different types of errors.

How to solve it
this is related to the faccessat2 system call. Due to the bug in runc, if your kernel does not support faccessat2, it will fail. There is an article saying that upgrading the kernel to 5.8 or above may work well, but I have tried it hard, because the kernel with the problem is 5.10
Method 1: update runc >= 1.0.0-rc93

Method 2: — privileged switch to run the container

Specific implementation of method 1:

View the original runc version

runc -v

Download version 1.0.0-rc95 of runc.amd64

Download address: releases · opencontainers/runc · GitHub

Name change and Execution Authority

mv runc.amd64 runc && chmod +x runc

View and back up the original runc

whereis runc

Some systems are in the /usr/bin/ directory, some systems are in the /usr/local/bin/ directory, the following commands are in the /usr/local/bin/ directory, the following commands are in the /usr/bin/ directory, change the directory yourself

mv /usr/local/bin/runc /usr/local/bin/runcbak

Overwrite the original runc

cp runc /usr/local/bin/runc

View the new version of runc

runc -v

Restart docker

systemctl restart docker

Method 2: concrete implementation

Docker run execution

docker run --privileged=true -p 8080:8080 tomcat:8

Add in docker-compose.yml

version: '2'
services:
    tomcat:
     container_name: tomcat
     image: tomcat:8
     ports:
         - '8080:8080'
     environment:
         - TZ=Asia/Shanghai
     privileged: true
     restart: always

[Solved] Error running tomcat8: Address localhost:80 is already in use

Error running tomcat8: Address localhost:80 is already in use

1. Problems

Tomcat startup error: Error running tomcat8: Address localhost:80 is already in use

2. Solution

2.1 port 8080 is modified

Modify the server.xml file in E:\software\apache-tomcat-8.5.81\conf back.

TomcatJSON parse error: Invalid UTF-8 [How to Solve]

After deployment on the server, it is found that many places report 400 error, which has a unified feature of transmitting Chinese to the back-end interface

Solution:

1. configure the Tomcat server transmission encoding format specification:

Edit the tomcat/conf/server.xml file and add the encoding attribute: URIEncoding=”UTF-8″ to the Connector tag

2. Edit the tocmat/bin/catalina.bat file and add the following attribute: set JAVA_OPTS=%JAVA_OPTS% -Dfile.encoding=UTF-8

3. the most important step is to restart through shutdown and startup under the bin directory of Tomcat

[Solved] Nacos Serve Local Startup Error: Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCre

Environmental Science:

Nacos-server-2.0.4

Windows.8.1

nacos-server-2.0.4\nacos\bin\startup.cmd execute error

Error message: Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException

Reason for error: Nacos defaults to the cluster startup mode

Modify as shown in the figure to start a single machine

set MODE="standalone"

Start successful

Other solutions:

Start by command

startup.cmd -m standalone

Failed to scan osdt_cert.jar & osdt_core.jar [How to Solve]

java.io.FileNotFoundException: D:\WorkSpace\repository\com\oracle\ojdbc\oraclepki\oracle.osdt\osdt_cert.jar (系统找不到指定的路径。)
java.io.FileNotFoundException: D:\WorkSpace\repository\com\oracle\ojdbc\oraclepki\oracle.osdt\osdt_core.jar (系统找不到指定的路径。)

The reason for the problem is the dependency added in POM and the built-in dependence of toCat on JSP support, which is used to compile JSP.

<dependency>
  <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-jasper</artifactId>
</dependency>

Solution: shield the jar package:
method 1: add the following codes in the startup class:

System.setProperty(org.apache.tomcat.util.scan.Constants.SKIP_JARS_PROPERTY,"*.jar");

Method 2: add the following codes in application.yml:

server:
  tomcat:
    additional-tld-skip-patterns:
      - osdt_cert.jar
      - osdt_core.jar

[Solved] Tomcat Server Error: java.lang.NullPointerException Csonsole Error ClassNotFoundException: com.mysql.jdbc.Driver

tomcat Server Error:  java.lang.NullPointerException
Type Exception Report

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

java.lang.NullPointerException
	com.gxa.login.dbutils.DBUtils.executeQuery(DBUtils.java:26)
	com.gxa.login.dao.LoginDao.queryInfo(LoginDao.java:16)
	com.gxa.login.service.LoginService.login(LoginService.java:15)
	com.gxa.login.service.LoginServlet.doPost(LoginServlet.java:27)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Note The full stack trace of the root cause is available in the server logs.

 

An error is also reported in the console

Obviously, the driver was not found

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

java.sql.SQLException: No suitable driver found for jdbc: mysql://localhost:3306

Solution: check whether the jar package is correctly placed under web/WEB-INF/lib

Add to the directory to correctly identify and use:

 

[Solved] Tomcat Startup Error: A child container failed during start、LifecycleException: Failed to start component

An error is reported when Tomcat is started. The error contents are as follows

WARNING: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost]]
	at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
	at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)
	at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:302)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:732)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.startup.Tomcat.start(Tomcat.java:341)
	at org.apache.tomcat.maven.plugin.tomcat7.run.AbstractRunMojo.startContainer(AbstractRunMojo.java:1238)
	at org.apache.tomcat.maven.plugin.tomcat7.run.AbstractRunMojo.execute(AbstractRunMojo.java:592)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:972)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:293)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:196)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
	at org.codehaus.classworlds.Launcher.main(Launcher.java:47)

The code change adds the following servlet dependency, and it starts successfully if you remove it, but it reports an error if you remove the reference to the project.
The reason is that adding the servlet dependency caused a conflict with another dependency when packaging.

Solution

You only need to add the scope tag in the dependency to exclude the servlet-api we introduced when packaging the project, as shown below

 

Classification of scope

Maven’s default dependency configuration items, the default value of scope is compile, the project is often silly to distinguish between the direct default. Today to sort out maven’s scope.

  • compile: the default is compile, nothing is configured, which means compile. compile means that the dependent project needs to participate in the compilation of the current project, of course, the subsequent test, runtime also participate in it, is a relatively strong dependency. This is a strong dependency. It is usually included when packaging.
  • test: The scope is test, which means that the dependent project is only involved in the test-related work, including the compilation and execution of the test code. Typical examples are junit.
  • runntime: The dependent project does not need to be involved in the compilation of the project, but it is required to be involved in the later testing and runtime cycles. Compared with compile, it just skips the compilation. To be honest, in the terminal project (non-open source, internal system), the difference with compile is not very big. The API jar corresponding to the implementation of JSR×××× is compiled, and the specific implementation is runtime, which is enough for compile to know the interface. oracle jdbc driver package is a good example, and the general scope is runntime. I can use A to achieve it, or B to achieve it.
  • provided: provided means that it can be packaged without being packaged in, and other facilities (Web Container) will provide it. In fact, the dependency can theoretically participate in the compile, test, run, etc. cycle. It is equivalent to compile, but with the exclude action done during the packaging phase.
  • system: In terms of involvement, it is the same as provided, but the dependencies are not grabbed from the maven repository, but from the local filesystem.