I run my web application with Payara with java -jar webapp.war
How do I set where the this Payara instance would log, for example I want to set it to /var/log/mywebapp.log or just relative to the Uber Jar file, what would be the command to pass?
My goal is to tail the logs from ssh so the log needs to have a path.
You can do it using from command line java -jar payara-micro.jar --logToFile /path/file.log or you can do it programmatically using PayaraMicro.getInstance().setUserLogFile("/path/file.log").bootStrap();, but I don't know if you need to use embbeded payara for do this on the main method. You can even create a logging.properties file and configure it, so you use --logProperties logging.properties argument when run your jar file.
Related
I'm trying to run Spring Boot executable-jar built using spring-boot-maven-plugin on a Linux machine. The machine has multiple jdks installed, the one on PATH is jdk8 and changing it is unfortunately not an option. My executable-jar however needs jdk17, so when I just launch it as is I get UnsupportedClassVersionError.
I was following the official documentation and created the corresponding .conf file to override JAVA_HOME. But this does not seem to solve the issue:
[root#ios-maket updater-new]# ls
updater-new-3.0-SNAPSHOT.conf updater-new-3.0-SNAPSHOT.jar
[root#ios-maket updater-new]# cat updater-new-3.0-SNAPSHOT.conf
JAVA_HOME=/opt/jdk-17/bin/java
[root#ios-maket updater-new]# ./updater-new-3.0-SNAPSHOT.jar
Application is running as root (UID 0). This is considered insecure.
Exception in thread "main" java.lang.UnsupportedClassVersionError...
On the other hand if I run it manually everything works fine:
[root#ios-maket updater-new]# /opt/jdk-17/bin/java -jar ./updater-new-3.0-SNAPSHOT.jar
[main] INFO com.icl.ios.fias.updaternew.UpdaterNew - Starting UpdaterNew using Java 17.0.6
What am I doing wrong?
Setting JAVA_HOME is not enough, you also need to set PATH to point to JAVA_HOME/bin.
JAVA_HOME=/opt/jdk-17
PATH=${JAVA_HOME}/bin:$PATH
java -jar updater-new-3.0-SNAPSHOT.jar
Try running the jar with -Dloader.path to specify the config manually.
java -Dloader.path=./updater-new-3.0-SNAPSHOT.conf -jar ./updater-new-3.0-SNAPSHOT.jar
If this still does not work, then probably there is an issue with your config file, but from what I can see, your config file looks okay, unless the java path is incorrect.
I have created a symlink for a spring boot executable jar and i am able to start the application. I want to customize the logs path, pid folder etc.
Went through the customizing the startup of this script.
But I could not find where to store the custom script and how it can be linked to executable application jar. Could you please assist?
Create a script with name your-app.service, place this script in /etc/systemd/system directory.
Installation as a systemd Service, using Java System Properties (VM Arguments):
[Unit]
Description= Spring Boot App
After=syslog.target
[Service]
User=myapp
ExecStart=java -Dspring.application.name=example -Dlogging.file=/opt/spring-boot-app/log/app.log -Dspring.pid.file=/opt/spring-boot-app/app.pid -jar /opt/spring-boot-app/app.jar
SuccessExitStatus=200
[Install]
WantedBy=multi-user.target
Or pass throught via program arguments:
java -jar /opt/spring-boot-app/app.jar --spring.application.name=example --logging.file=/opt/spring-boot-app/log/app.log --spring.pid.file=/opt/spring-boot-app/app.pid
References in here and here.
logging.file= # Log file name (for instance, myapp.log). Names can
be an exact location or relative to the current directory.
spring.pid.file= # Location of the PID file to write (if
ApplicationPidFileWriter is used).
I try to deploy the sprin boot jar file into a remote Linux server and run it throw java -jar command.
The command was much like below:
ssh root#xxx.com:/myjdk_path/bin/java -jar /tmp/target.jar
The problem is that there was no any log dir been created while i running the command.
The sprin boot app was created by the spring.io site,it's a normal app then i put one single line "logging.file=./log/my.log" into application.properties.
But it works(the log dir can be created) when i just logged into the target server and type the command in the ssh console.
The sprin boot version is 2.05 and i've test version 1.5.16 still the same.
And i aslo test it in both Ubuntu and Centos servers,nothing haapens too.
Really appreciate if you can give a clue on this!
Thanks all you guys , it turns out my fault, the reason is that I am using a relative log path ,and I run that java -jar command out side the shell directory.
old command:ssh root#xxx.com:/myjdk_path/bin/java -jar /tmp/target.jar
new command:ssh root#xxx.com:cd /tmp; /myjdk_path/bin/java -jar target.jar
the log dir was been created for the old command ,but it in the user home path(for this command is the ROOT user),but not in the /tmp path.
so my stupid check steps missing that point,and thought there is no log dir been created!
I have built my own hippo project based on hippo-maven-archetype.
I have prepared the PostgreSQL configuration of repository and created hippo database.
Then I've built my app and run it by maven (mvn -Pcargo.run -Drepo.path=storage).
All is ok, Postgresql repository was initialized successsfully and hippo works.
Now I am trying to deploy my project on my Linux server, as described here, using tomcat 8 and java 8.
All is ok, except that the repository does not initializing in any way.
Cms Web-page always redirects to localhost/cms/wicket/bookmarkable/org.hippoecm.frontend.NoRepositoryAvailablePage.
At tomcat startup there are no errors, but also there are no messages about bootstrapping the repository.
After successful startup, log files contain exception: java.lang.IllegalArgumentException: The resource path [WEB-INF/storage] is not valid
Tomcat java command prompt (as ps shows:)
/usr/bin/java -Djava.util.logging.config.file=/opt/apache-tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -server -Xmx512m -Xms128m -XX:PermSize=128m -Drepo.path=storage -Drepo.config=file:/opt/apache-tomcat/conf/repository.xml -Drepo.bootstrap=true -Dlog4j.configuration=file:/opt/apache-tomcat/conf/log4j.xml -Djava.endorsed.dirs=/opt/apache-tomcat/endorsed -classpath /opt/apache-tomcat/bin/bootstrap.jar:/opt/apache-tomcat/bin/tomcat-juli.jar -Dcatalina.base=/opt/apache-tomcat -Dcatalina.home=/opt/apache-tomcat -Djava.io.tmpdir=/opt/apache-tomcat/temp org.apache.catalina.startup.Bootstrap start
Any ideas?
It's a best practice to put your repository storage outside of your web application. I would advise you to explicitly set the storage location by using the repo.path system property to a full qualified location on the filesystem instead of a relative path like you do now. With Tomcat you could specify this in your setenv.sh file by appending the following parameter to your CATALINA_OPTS.
CATALINA_OPTS="-Xmx1024m -Drepo.path=/opt/cms-storage/"
You also need to take into account that the configured workspace will be extracted to a separate file within this storage directory, so if you change something within the repository.xml you will probably have to change the existing workspace.xml as well. As of version 7.9.7 Hippo supports running the entire stack on Java 8. See the release notes for more information and what has changed.
I have a problem with starting Jetty via the startup command /etc/init.d/jetty. When I execute the command the following output is generated:
/etc/init.d/jetty start
Starting Jetty servlet engine.:
Jetty Rotate logs
Jetty servlet engine started, reachable on http://jagadguru:80/.: jetty.
It does start successfully when I type java -jar start.jar in my Jetty directory.
Can anyone help me with this?
This is likely a file permission issue. Even if you are running the start script with sudo, the script defines a jetty user (default is jetty). I had an issue similar to this where my permissions on /tmp prevented jetty from creating a file there. I adjusted the permissions on /tmp and all is well! The jetty user also needs permissions on the jetty folder of course.
Also, for checking if Jetty is finding java correctly, run sudo service jetty check
It's probably an issue due to wrong permissions on some work or log folder. I assume the start script tries to change the user and therefore doesn't has the same permissions as the one you use when running Jetty via "java -jar".
Another possibility is that you don't have JAVA_HOME set and the start script doesn't find your java bin.
Please attach some kind of log file as it is really hard to say more without more detailed information.
As answered here, the default configuration for Jetty in /etc/default/jetty only allows connections from localhost, you need to set JETTY_HOST to 0.0.0.0 to allow Jetty to accept connections from any host.
Add the following line to /etc/default/jetty:
JETTY_HOST 0.0.0.0