Changing port when running Jetty using jetty-runner - java

I'm executing the following command line:
java -jar C:\WorkArea\jetty-runner.jar c:\name.war --port 9090
I'm expecting it to run on port 9090 but it keeps on running using port 8080 which is the default.
What am I missing?
When running through eclipse itself, it is using 8888 so it's not taking this info from there, where/how else can I control the port?
Thanks

The documentation of the Jetty Runner suggests that the port option should be passed before the WAR file:
java -jar C:\WorkArea\jetty-runner.jar --port 9090 c:\name.war

Related

Web server failed to start. Port 8080 was already in use

I am trying to develope a webapp using spring boot in STS. While running my app i am getting
Description:
Web server failed to start. Port 8080 was already in use.
Action:
Identify and stop the process that's listening on port 8080 or
configure this application to listen on another port.
I have tried to close the application for port 8080. I found the PID for the port and terminated it using
taskkill /F /PID pidname
I restarted the STS and tried to run again but its throwing the same error.
If port is acquired by some OS thread, it would be a bit tricky to stop it. Although it's not always great solution, but if you still want to continue with your development without any issue you can use this alternative solution (as you are in development environment).
Here is another thing you can use. You can replace the default port for Spring Boot server to some other port number.
For server port the property is server.port.
If you are using application.properties file:
server.port=8081
It will start server on port 8081.
Similarly, you can do the same if using an application.yml file:
server:
port : 8081
Each file is loaded by Spring Boot if placed in the src/main/resources directory of a Maven application.
Your only other option (beside making port 8080 available or using another port for spring boot) is running the application in docker:
Create a Dockerfile in your application directory
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
Run in terminal
sudo docker build -t spring-app . && docker run -d -p 8080:8080 -t springapp
(This assumes you have docker installed, please install it if you don’t have it)

Not able to access the docker containerised java web app on exposed port

I have Java web app in docker container.
Now container is exposed on host's port 8080 from container's port 8080 by running docker run command.
docker run -d -p 8080:8080 --name myTomcat -v $(pwd)/out/artifacts/DockerJavaWebAppWarExploded:/usr/local/tomcat/webapps/ tomcat:latest
There is no other process running on 8080 port ,but i am not able to access the application from browser http://localhost:8080/.
Container logs :
Please help.
It would be appreciated.
Check if http://0.0.0.0:8080 returns values. If yes, you may add an enrty for 0.0.0.0 in your hosts file.

Debug embedded tomcat on heroku

I'm working on a Java web application. I already deploy it to heroku. Now I'm trying to remote debug my application using IntelliJ with no results. To deploy it I use git, then heroku starts it reading and executing the Procfile. And here is the problem. Everywhere I see that to debug I must use this line in my Procfile: web: java -agentlib:jdwp=transport=dt_socket,server=y,address=9090,suspend=n -jar target/myapp.jar. But I can't put this line on my Procfile because I execute my app using web: sh target/bin/webapp and not java. There's some workaround to simply debug my application.
You'll need Heroku Exec and the Heroku Java CLI.
First, put your agentlib args into the JAVA_TOOL_OPTIONS env var:
$ heroku config:set JAVA_TOOL_OPTIONS="-agentlib:jdwp=transport=dt_socket,server=y,address=9090,suspend=n"
This way, the java process in your target/bin/webapp script will pick it up automatically.
Then run:
$ heroku ps:forward 9090
And you can connect to localhost:9090 from your IDE.

JMX and Debugging on Tomcat inside Docker

I am trying to setup IntelliJ to connect to a Tomcat instance running in a Docker container. I would like to be able to use remote debugging and also deploy remotely using JMX.
I can enable remote debugging using the environment variables
JPDA_ADDRESS=8000
JPDA_TRANSPORT=dt_socket
and by starting Tomcat with catalina.sh jpda run, so remote debugging works without a problem.
I can also do this alternatively with
CATALINA_OPTS='-agentlib:jdwp=transport=dt_socket,address=8000,suspend=n,server=y'
and then I don't need to use catalina.sh jpda run
No matter what I do, I cannot get JMX to work. I verified that I have catalina-jmx-remote.jar in /usr/local/tomcat/lib`.
I have tried setting CATALINA_OPTS and JAVA_OPTS to
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.port=1099
-Dcom.sun.management.jmxremote.rmi.port=1099
-Djava.rmi.server.hostname=192.168.99.100
-Dcom.sun.management.jmxremote.ssl=false
I have verified that 192.168.99.100 is the IP of my docker machine. I have tried connecting to JMX with VisualJM and IntelliJ, it does not work. I have verified that the port 1099 is open and available from the host.
Tomcat is receiving the JMX args
20-Apr-2016 23:50:14.019 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.rmi.port=1099 -Djava.rmi.server.hostname=192.168.99.100 -Dcom.sun.management.jmxremote.ssl=false
Why can't I get JMX to work? There is no information available in any logs and this will not work no matter what I try.
Edit: lsof -i :1099 shows nothing running on that port
I am running on Mac OS X. It is a docker-machine but I believe docker uses virualbox on mac because it can't run containers natively.
I have mapped the port. docker ps shows 0.0.0.0:1099->1099/tcp, 0.0.0.0:8000->8000/tcp, 0.0.0.0:8080->8080/tcp. Ports 8080 and 8000 work so 1099 should be mapped correctly too.
I was able to connect when I used 0.0.0.0 for jmxremote.host and server.hostname
HOST=0.0.0.0
java -Xmn100M -XX:+PrintGCDetails -XX:MinHeapFreeRatio=20 -XX:MaxHeapFreeRatio=40 -Xmx384M $JAVA_OPTS\
-Dcom.sun.management.config.file=/opt/app/management.properties \
-Djava.util.logging.config.file=/opt/app/logging.properties \
-Dcom.sun.management.jmxremote.port=$JMX_PORT \
-Dcom.sun.management.jmxremote.rmi.port=$JMX_PORT \
-Dcom.sun.management.jmxremote.host=$HOST \
-Djava.rmi.server.hostname=$HOST \
-jar /opt/app/app.jar

Address binding issue

I am trying to run a web application (which is a servlet + gradle project). I am using Jetty to run the application. When I run the application , I am getting the error:
Address already in use
Could not execute build using Gradle distribution 'https://services.gradle.org/distributions/gradle-2.0-bin.zip'.
When, I enter localhost:8080 , I used to get jenkins default page, So I uninstalled jenkins and tried again, but getting the same error.
Please help in resolving this issue, also how do we get to know which application is running on corresponding port?
You can use the command "netstat". Look for the line in which the column "remote address" ends with ":8080".
Depending on the OS you're running:
Windows:
netstat -b -n -a -p TCP
The process is printed above the line.
Linux:
netstat -a -n -p | grep 8080
The process is printed as the last column of the line.

Categories

Resources