Java 修复 apache v9.0 Server Tomcat v9.0 Server at localhost failed to start 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39310432/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
fixing apache v9.0 Server Tomcat v9.0 Server at localhost failed to start error
提问by Hymany
i have a simple java ee project which i need to send an email to a user, i found that it is possible with javamail and the gmail free smtp.
我有一个简单的 java ee 项目,我需要向用户发送电子邮件,我发现使用 javamail 和免费的 gmail smtp 是可能的。
my mail sender implementation:
我的邮件发件人实现:
package duck.reg.pack;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
@WebServlet("/sendmailtls")
public class SendMailTLS extends HttpServlet {
public static void main(){
final String username = "[email protected]";
final String password = "Password";
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("[email protected]"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("[email protected]"));
message.setSubject("Testing Subject");
message.setText("Dear Mail Crawler,"
+ "\n\n No spam to my email, please!");
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
}
now the problem is that when ever i compile my program i get apache error saying:
现在的问题是,当我编译我的程序时,我收到 apache 错误说:
'Starting tomcat v9.0 Server at localhost' has encountered a problem. Server Tomcat v9.0 Server at localhost failed to start.
'Starting tomcat v9.0 Server at localhost' 遇到问题。服务器 Tomcat v9.0 服务器在 localhost 启动失败。
and i found that if i remove
我发现如果我删除
Session session = Session.getInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
it compile just fine.
它编译得很好。
回答by Pradeep
Apache server normally runs on port 8080 and this port might be busy so try to free that port . First find that which all process are running on port 8080 through cmd , command to find is
Apache 服务器通常在端口 8080 上运行,此端口可能很忙,因此请尝试释放该端口。首先通过cmd找到8080端口上运行的所有进程,要查找的命令是
netstat -ano find "8080"
netstat -ano 找到“8080”
It will list the PID and using that PID kill that process through cmd, command to kill process is
它将列出PID并使用该PID通过cmd杀死该进程,杀死进程的命令是
taskkill /f /pid PIDno
taskkill /f /pid PIDno
回答by Hemantha
If there is a error in the project web.xml file (Not the server web.xml file) it prevents the starting the server starting.check and verify the web.xml and other xml files related to the project. For me when i fix the errors in web xml file server ran correctly.sometimes the server cache shows the previous errors in web pages which you are developing.beware of that also.
如果项目 web.xml 文件(不是服务器 web.xml 文件)中有错误,它会阻止服务器启动。检查并验证 web.xml 和其他与项目相关的 xml 文件。对我来说,当我修复 web xml 文件中的错误时,服务器正确运行。有时服务器缓存会显示您正在开发的网页中的先前错误。也要注意这一点。
回答by Lithin
In my case a a jar in .m2 folder was corrupted. I deleted it and did a maven install . It downloaded the jar again and this time my server was able to build
在我的情况下,.m2 文件夹中的 jar 已损坏。我删除了它并进行了 maven install 。它再次下载了 jar,这次我的服务器能够构建
回答by syclone
I had this error and i noticed that beneath the nav bar the button 'terminate' was coloured in red. I clicked it then the error was gone.
我遇到了这个错误,我注意到导航栏下方的“终止”按钮是红色的。我点击它然后错误消失了。
回答by Viveksuriyan
web.xml is the culprit here most of the time.
大多数情况下,web.xml 是罪魁祸首。
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Spring MVC Application</display-name>
<servlet>
<servlet-name>springMVC</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springMVC</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Copy paste the content in your web.xml file
将内容复制粘贴到 web.xml 文件中
If you have defined "<?xml version="1.0" encoding="UTF-8"?>
" by mistake remove it.
如果您<?xml version="1.0" encoding="UTF-8"?>
错误地定义了“ ”,请将其删除。