IntelliJ, can't start simple web application:

2019-01-10 19:58发布

问题:

I'm trying to make a simple web app in IntelliJ by following this tutorial: http://wiki.jetbrains.net/intellij/Creating_a_simple_Web_application_for_Tomcat_in_IntelliJ_IDEA_12

I believe my Tomcat is installed correctly since I see the tomcat pictures when I go to http://localhost:8080/

I've followed all the steps up until the part it tells me to run index.jsp, at which point I get the error:

Error: Exception thrown by the agent : java.net.MalformedURLException: Local host name unknown: java.net.UnknownHostException: nodename nor servname provided, or not known

I see this in the log:

Application Server was not connected before run configuration stop, reason:
           Unable to ping server at localhost:1099

This 1099 comes from the JMX port in Run -> Edit Configurations.

How do I fix this?

回答1:

To fix this you need add your machine name in the /etc/hosts file to point to localhost(127.0.0.1).

You can find your machine name by running the following command:

$ hostname
macbook-pro

From the output above you know your hostname is "macbook-pro". Edit "/etc/hosts" file and add that name at the end of line that lists 127.0.0.1

127.0.0.1 localhost macbook-pro

Save the file.

Now you IntelliJ should be able to start your server.



回答2:

See that the tomcat you are using is compatible with the Java version. For me the issue was Tomcat-9 required Java-8. If you have a older version of Java, you could use Tomcat-7 to test.



回答3:

I added my hostname to /etc/hosts on localhost. Added JAVA_HOME but still it showed the same error. In the console, there was output:

Unable to start as CATALINA_BASE contains a colon (:) character

I solved the problem by going to Edit configurations -> Startup/Connection -> changing CATALINA_BASE value to the tomcat installation folder. Before that, it was

CATALINA_BASE:   C:\Program Files\Apache Software Foundation\Tomcat 8.0

which can't be correct on a linux machine ;)



回答4:

FYI Under certain network conditions your hostname may change or be incorrect. If you are on a mac the following will let you set your hostname fairly permanently:

sudo scutil --set HostName correct-name


回答5:

This appears to be a problem with the way mac is handling reading the /etc/hosts file. See for example http://youtrack.jetbrains.com/issue/IDEA-96865

Adding the hostname to the hosts file as bond described should not be required, but it does solve the problem.



回答6:

My problem was that tomcat 8 and higher are not compatible with java 6. Changing to java 7 solved it.



回答7:

I meet this question when i use intellij 15.0,then i update to 15.02 version. after that, I edit configurations and reset the Default JRE to my own JRE.It works well for me;



回答8:

I solve this problem adding the environment variables JAVA_HOME(C:\Program Files\Java\jdkx.x.x_xx) and JRE_HOME.



回答9:

This error came to me when I configured (wrong) 3 Gb memory where there was none. IntelliJ does shows the real error message (Could not reserve enough space for object heap) in the Output frame. I was confused, and attracted by the message in the Event Log, which is to be ignored in this case.



回答10:

None of the answers above worked for me. In the end I figured out it was an configuration error (I used the android SDK and not Java SDK for compilation).

Got to [Right Click on Project] --> Open Module Settings --> Module --> [Dependendecies] and make sure you have configured and selected the Java SDK (not the android java sdk)



回答11:

I had similar issue when I entered very big port here:

But when I corrected it to something smaller which is in offset range:

Issue was resolved.



回答12:

On top pointing my hostname to 127.0.0.1 in hosts (just run hostname in cmd to get it) as well as doing what David GC mentioned, for me the error cleared and debugging worked when I went into the tomcat configuration and changed the debugging startup script from startup.bat (which was just my monkeying around) back to the catalina.bat start default.



回答13:

I added the following VM Options and it worked for me:

-Dcom.sun.management.jmxremote= 
-Dcom.sun.management.jmxremote.port=1099 
-Dcom.sun.management.jmxremote.authenticate=false 
-Dcom.sun.management.jmxremote.ssl=false


回答14:

I had the same problem of "Unable to ping server at localhost:1099" while I was using intellij 2016 version.

However, as soon as I upgraded it to 2017 version(Ultimate 2017.1) which is installed using "ideaIU-2017.1.exe" the problem disappeared.



回答15:

I had same issue and my mistake was, I was trying to start tomcat server with incompatible version of JDK and installed Apache tomcat server. In my case I had installed JDK 7 with Apache tomcat 9. For Apache 9 JDK should be >= 8.

For compatibility check this https://tomcat.apache.org/whichversion.html



回答16:

I had this issue when running Tomcat 6.0.53 on Mac OS Sierra with Intellij IDEA to deploy Spring projects. This problem was solved after changing the Tomcat version to the 'tar.gz' one from official site. It seems the 'zip' one is for windows.



回答17:

I had same problem. In "Edit Configurations.." -> "Tomcat Server" I changed JRE from "Default" to my current version with SDK directory address (like C:\Program Files\Java\jdk1.8.0_121\jre)

My Tomcat version is 8.5.31