Skip to content

Commit ca30101

Browse files
committed
add helpful message for all run application
1 parent 72dd941 commit ca30101

File tree

2 files changed

+46
-38
lines changed

2 files changed

+46
-38
lines changed

core/deployment/src/main/java/io/quarkus/deployment/dev/IsolatedDevModeMain.java

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -113,50 +113,36 @@ public void accept(Integer integer) {
113113
while (rootCause.getCause() != null) {
114114
rootCause = rootCause.getCause();
115115
}
116-
if (rootCause instanceof BindException) {
117-
int port = ConfigProviderResolver.instance().getConfig()
118-
.getOptionalValue("quarkus.http.port", Integer.class).orElse(8080);
119-
log.error("Port " + port + " seems to be in use by another process. " +
120-
"Quarkus may already be running or the port is used by another application.");
121-
if (System.getProperty("os.name").startsWith("Windows")) {
122-
log.info("Use 'netstat -a -b -n -o' to identify the process occupying the port.");
123-
log.info("You can try to kill it with 'taskkill /PID <pid>' or via the Task Manager.");
124-
} else {
125-
log.info("Use 'netstat -anop | grep " + port + "' to identify the process occupying the port.");
126-
log.info("You can try to kill it with 'kill -9 <pid>'.");
127-
}
128-
deploymentProblem = rootCause;
129-
} else {
116+
if (!(rootCause instanceof BindException)) {
130117
deploymentProblem = t;
131118
if (!augmentDone) {
132119
log.error("Failed to start quarkus", t);
133120
}
134-
}
135-
if (!context.isAbortOnFailedStart()) {
136-
//we need to set this here, while we still have the correct TCCL
137-
//this is so the config is still valid, and we can read HTTP config from application.properties
138-
log.info("Attempting to start hot replacement endpoint to recover from previous Quarkus startup failure");
139-
if (RuntimeUpdatesProcessor.INSTANCE != null) {
140-
Thread.currentThread().setContextClassLoader(curatedApplication.getBaseRuntimeClassLoader());
141-
142-
try {
143-
if (!InitialConfigurator.DELAYED_HANDLER.isActivated()) {
144-
Class<?> cl = Thread.currentThread().getContextClassLoader()
145-
.loadClass(LoggingSetupRecorder.class.getName());
146-
cl.getMethod("handleFailedStart").invoke(null);
121+
if (!context.isAbortOnFailedStart()) {
122+
//we need to set this here, while we still have the correct TCCL
123+
//this is so the config is still valid, and we can read HTTP config from application.properties
124+
log.info(
125+
"Attempting to start hot replacement endpoint to recover from previous Quarkus startup failure");
126+
if (RuntimeUpdatesProcessor.INSTANCE != null) {
127+
Thread.currentThread().setContextClassLoader(curatedApplication.getBaseRuntimeClassLoader());
128+
try {
129+
if (!InitialConfigurator.DELAYED_HANDLER.isActivated()) {
130+
Class<?> cl = Thread.currentThread().getContextClassLoader()
131+
.loadClass(LoggingSetupRecorder.class.getName());
132+
cl.getMethod("handleFailedStart").invoke(null);
133+
}
134+
RuntimeUpdatesProcessor.INSTANCE.startupFailed();
135+
} catch (Exception e) {
136+
close();
137+
log.error("Failed to recover after failed start", e);
138+
//this is the end of the road, we just exit
139+
//generally we only hit this if something is already listening on the HTTP port
140+
//or the system config is so broken we can't start HTTP
141+
System.exit(1);
147142
}
148-
RuntimeUpdatesProcessor.INSTANCE.startupFailed();
149-
} catch (Exception e) {
150-
close();
151-
log.error("Failed to recover after failed start", e);
152-
//this is the end of the road, we just exit
153-
//generally we only hit this if something is already listening on the HTTP port
154-
//or the system config is so broken we can't start HTTP
155-
System.exit(1);
156143
}
157144
}
158145
}
159-
160146
}
161147
} finally {
162148
Thread.currentThread().setContextClassLoader(old);

core/runtime/src/main/java/io/quarkus/runtime/ApplicationLifecycleManager.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.quarkus.runtime;
22

3+
import java.net.BindException;
34
import java.util.Locale;
45
import java.util.Objects;
56
import java.util.Set;
@@ -14,6 +15,7 @@
1415
import javax.enterprise.inject.spi.BeanManager;
1516
import javax.enterprise.inject.spi.CDI;
1617

18+
import org.eclipse.microprofile.config.spi.ConfigProviderResolver;
1719
import org.graalvm.nativeimage.ImageInfo;
1820
import org.jboss.logging.Logger;
1921
import org.wildfly.common.lock.Locks;
@@ -139,8 +141,28 @@ public static void run(Application application, Class<? extends QuarkusApplicati
139141
}
140142
} catch (Exception e) {
141143
if (exitCodeHandler == null) {
142-
Logger.getLogger(Application.class).errorv(e, "Failed to start application (with profile {0})",
143-
ProfileManager.getActiveProfile());
144+
Throwable rootCause = e;
145+
while (rootCause.getCause() != null) {
146+
rootCause = rootCause.getCause();
147+
}
148+
Logger applicationLogger = Logger.getLogger(Application.class);
149+
if (rootCause instanceof BindException) {
150+
int port = ConfigProviderResolver.instance().getConfig()
151+
.getOptionalValue("quarkus.http.port", Integer.class).orElse(8080);
152+
applicationLogger.error("Port " + port + " seems to be in use by another process. " +
153+
"Quarkus may already be running or the port is used by another application.");
154+
if (System.getProperty("os.name").startsWith("Windows")) {
155+
applicationLogger.info("Use 'netstat -a -b -n -o' to identify the process occupying the port.");
156+
applicationLogger.info("You can try to kill it with 'taskkill /PID <pid>' or via the Task Manager.");
157+
} else {
158+
applicationLogger
159+
.info("Use 'netstat -anop | grep " + port + "' to identify the process occupying the port.");
160+
applicationLogger.info("You can try to kill it with 'kill -9 <pid>'.");
161+
}
162+
} else {
163+
applicationLogger.errorv(rootCause, "Failed to start application (with profile {0})",
164+
ProfileManager.getActiveProfile());
165+
}
144166
}
145167
stateLock.lock();
146168
try {

0 commit comments

Comments
 (0)