77

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?

valiano
  • 16,433
  • 7
  • 64
  • 79
Popcorn
  • 5,188
  • 12
  • 54
  • 87

29 Answers29

72

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.

bond
  • 11,236
  • 7
  • 48
  • 62
  • 22
    Just to mention - that in my case it actually was a typo in JVM argument that was causing this – lia ant Jul 14 '15 at 13:47
  • Note: use sudo when opening the /etc/hosts file as it is READ-ONLY – Alex Wilson Dec 19 '16 at 19:31
  • I had this same error when trying to run a Spring Boot application from STS "Run As" -> "Spring Boot App". After adding my Mac's hostname pointing to localhost in the hosts file, it worked. Thanks bond! – E3G May 11 '17 at 17:53
  • 4
    If your going to give an OS specific answer mention that first. – Philip Rego Jul 24 '19 at 16:32
22

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.

Ujjwal Singh
  • 4,908
  • 4
  • 37
  • 54
  • 1
    This was the issue for me. I changed to JDK 1.8 from JDK 1.7. In the Run/Debug configurations --> Edit Artifacts. changed the SDK version and Project SDK – Shardayyy Feb 24 '17 at 14:27
7

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 ;)

vasil todorov
  • 145
  • 1
  • 11
5

For those who encounter this when you just recently updated IntelliJ (In my case 2019.2).

I am using JBoss server so i tried to run standalone.bat in the command line and I saw the real issue on the console.

It can be different to yours, but in my case I saw:

failure description: "WFLYSRV0137: No deployment content with

And on that error I was able to fix this by removing the items (war or ear) inside the <deployments/> node in my standalone.xml

Hope this helps for those using JBoss+IntelliJ

pvma
  • 403
  • 8
  • 14
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
Trideep Gogoi
  • 179
  • 1
  • 4
  • 1
    This doesn't solve the problem. For me `sudo scutil --get HostName` returns the correct hostname but IntelliJ still has the issue OP asked about. Adding hostname to `/etc/hosts`, as @bond suggested, fixed the issue. – ehsanullahjan May 21 '15 at 16:10
  • This solved my problem ! My hostname contained a dot. I set it as simple as possible; set it in the hosts file as explained above and it works. – Bancarel Valentin Jan 10 '18 at 21:09
3

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.

Beth
  • 31
  • 3
3

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

fxlex
  • 65
  • 1
  • 8
  • 3
    More generally, Tomcat X might be incompatible with Java Y. Check [here](http://tomcat.apache.org/whichversion.html) for version compatibilities. – Beyamor Feb 05 '16 at 21:21
3

I had similar issue when I entered very big port here: enter image description here

But when I corrected it to something smaller which is in offset range: enter image description here

Issue was resolved.

Alex
  • 1,940
  • 2
  • 18
  • 36
  • Yes, port numbers are a 16 bit integer so only 0-65535 are available (and 0 is reserved, and 1-1023 can only be used by root/admin users). – Per Lundberg Oct 10 '18 at 13:03
3

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

ArsTV
  • 321
  • 3
  • 5
2

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.

Mike
  • 381
  • 1
  • 4
  • 12
2

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)

Johannes Staehlin
  • 3,680
  • 7
  • 36
  • 50
2

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;

user5091911
  • 123
  • 1
  • 2
2

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
1

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

cagigas
  • 49
  • 10
1

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.

Park JongBum
  • 1,245
  • 1
  • 16
  • 27
1

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.

Yushan ZHANG
  • 523
  • 5
  • 18
1

Setting project's SDK in IntelliJ (File > Project Structure > Project:Project SDK) worked for me

Pavlo Zvarych
  • 615
  • 2
  • 9
  • 13
1

If your tomcat contains file setenv.sh ([YOUR_CATALINA_HOME]/bin/setenv.sh) it may redefine the JAVA_OPTS variable that JIdea uses to set up JMX, so you have to add them there:

export JAVA_OPTS ="$JAVA_OPTS <whatever was in setenv.sh>"
echo $JAVA_OPTS
yggdraa
  • 2,002
  • 20
  • 23
1

Below is the error I observed :

enter image description here

to resolve, in my case, I exit intelliJ and renamed folder ".idea" to ".idea_old" (so that I don't loose old config) and restarted intelliJ, It created a new ".idea" folder and I provided new tomcat configuration. On running tomcat this issue was removed.

Shashank Bodkhe
  • 941
  • 10
  • 15
0

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.

Alkanshel
  • 4,198
  • 1
  • 35
  • 54
0

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

0

For me, it was a much different solution since it was running on a virtualbox, so I had to edit the hosts file and add the virtualbox as a localhost

127.0.0.1 VirtualBox-blahblah
3xCh1_23
  • 1,491
  • 1
  • 20
  • 39
0

In windows environment just check the PATH environment variable if Oracle JRE runtime refreshed the path and put himself at the very beginning of the path. In this case even if the JAVA_HOME AND JRE_HOME points to the correct JDK, the JRE will have precedence. And this case IntelliJ will not start Tomcat instance with the mentioned error message.

Miklos Krivan
  • 1,732
  • 20
  • 14
0

If you are using java 7 then make sure you have Tomcat 7

brew install tomcat@7

and update run configuration to Tomcat 7

Tomcat 9 is working with java 8

Tal Hakmon
  • 475
  • 5
  • 6
0

I'm leaving an answer for the jboss user.

If any of the people experiencing this error are using jboss, make sure the JBOSS_HOME location is correct.

Minchul Joh
  • 33
  • 1
  • 9
0

If we have the installed the compatible tomcat version for the application JAVA jdk version, we can resolve this issue easily.

In my case, when I am using Tomcat 10.1.0.M4 with JAVA JDK 1.8 I faced this issue. When I downgrade my tomcat version to 9.0.41, the issue resolved for me.

enter image description here

You can find the compatible tomcat version for the JAVA JDK here.. http://tomcat.apache.org/whichversion.html

enter image description here

Shobana T
  • 81
  • 3
0

It's already in comment mentioned by @lia ant but I think it should be an answer.

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

this can happen because of typo in VM options in Edit Configurations...

screenshot with field which can cause error

Michu93
  • 5,058
  • 7
  • 47
  • 80
0

In my case it was due java version issues[changed 1.8 version only with compatible with tomcat 9] just changing the version and pointing to correct one solved the issues.

0

just you need to check ,is it your tomcat version support your java or not for example jdk 1.8 didn't support tomcat 10.1. you should downgrade your tomcat version to 9

MrG
  • 11
  • 2