2

I'm using (almost) latest Intellij Ultimate 2022.1.1 (same with latest VS Code) with JDK 8 and maven 3.6.3 (can't upgrade)

When executing Maven build (as compile/package) and it fails (for example compilation error)

I can't rerun because port 1100 is still used by a java.exe process I must kill manually

As a work around I kill process in command line dynamically

FOR /F "tokens=5 delims= " %P IN ('netstat -a -n -o ^| findstr :1100') DO TaskKill.exe /F /PID %P

jps output :

RMI Registry not available at 11808:1099
Exception creating connection to: 11808; nested exception is:
        java.net.SocketException: Network is unreachable: connect

**EDIT **

Problem was due to environment variable MAVEN_OPTS jmxremote.port 1100 used for activate JMX for JConsole

-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=1100
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
  • Does your build work in plain command line? Why is the port 1100 used by a java process? By which one? – khmarbaise May 23 '22 at 13:39
  • Which process executes the maven build? You means from inside IntelliJ? Which version of IntelliJ do you use? Which version of Maven, JDK etc. do you use? Furthermore the error message would also be helpful... – khmarbaise May 23 '22 at 13:43
  • 1
    Your maven build should by default not require any network port. Sounds like there are tests running during the build. – Thorbjørn Ravn Andersen May 23 '22 at 14:28
  • 1
    Why do you use an old Maven version? 3.6.3 ??? In IntelliJ 2022.1.1 is by default Maven 3.8.1... furthermore and yes no port should be used by default... It sounds like one of your tests is using a port? Do you have spring boot tests via WebMVC or alike? – khmarbaise May 23 '22 at 14:36
  • Have a closer look at where it is stuck then. You can use `jps` at the command line to locate old processes you though about – Thorbjørn Ravn Andersen May 23 '22 at 14:37
  • Or simply just reboot your machine. – Thorbjørn Ravn Andersen May 23 '22 at 14:39
  • Check what process occupies the `1100` port and kill this process. Check for Windows: https://stackoverflow.com/q/48198/2000323 Check for Linux: https://www.tecmint.com/find-out-which-process-listening-on-a-particular-port/ – Andrey May 24 '22 at 09:21
  • @Andrey java.exe process called from Intellij I can kill, but why should I kill process every build – Ori Marko May 24 '22 at 09:25
  • @ThorbjørnRavnAndersen added bounty and more details to question – Ori Marko Jun 08 '22 at 09:13
  • @Andrey added bounty and more details to question, I can kill process, but I prefer to avoid keeping hanging processes – Ori Marko Jun 08 '22 at 09:13
  • @khmarbaise bounty and more details to question, it happen also on compiling, notice I'm using remote url repository – Ori Marko Jun 08 '22 at 09:14
  • @khmarbaise Maven 3.6 and older still allows an access to a plugin reporsitory with http. In Maven 3.7 and higher this protocol is blocked by default. But it exists an official workaround for this case. – Reporter Jun 08 '22 at 09:42
  • @Reporter good catch we are using http to connect to our repository – Ori Marko Jun 08 '22 at 09:45
  • @Reporter I know that there is blocking access to http repository which is introduced in Maven 3.8.1 (https://maven.apache.org/docs/3.8.1/release-notes.html) apart from that Maven 3.7 does not exist... – khmarbaise Jun 08 '22 at 12:27
  • `RMI Registry not available at 11808:1099` - this is very very wierd. Why is "11808" a host name here? – Thorbjørn Ravn Andersen Jun 08 '22 at 17:57
  • And _why_ do you modify your hosts file? What else has happened to it? – Thorbjørn Ravn Andersen Jun 08 '22 at 17:58
  • To answer the question "How can I automatically close the process?": You can use either `exec-maven-plugin` or `maven-antrun-plugin` to run a script that closes the process. However the other comment are correct in that its weird it's hanging in the first place. – Bragolgirith Jun 10 '22 at 18:57
  • Are you sure that you need attach jConsole to the maven process and not to the program compiled by maven? – Nick Jun 14 '22 at 08:11
  • @Nick Initially I tried to attach it while executing tests using maven – Ori Marko Jun 14 '22 at 08:14

1 Answers1

0

Intellij starts maven background process to import dependencies (and other things) and doesn't close it for faster re-run. This background process uses MAVEN_OPTS just like normal maven process and listens port preventing other maven processes from starting

Remove global MAVEN_OPTS and set -D*.jmxremote.* perameters only for the required process

  • You can set perameters in intellij Run/Debug Configuration

  • When run from terminal: export MAVEN_OPTS="" && mvn package

  • For run tests try this

Nick
  • 3,691
  • 18
  • 36