NSSM - the Non-Sucking Service Manager & Jetty - java

I am trying to use the NSSM - the Non-Sucking Service Manager to run Jetty that is included with Solr as a Windows Service. Everything works fine by placing Java.exe in my C:\solr folder and setting up NSSM by pointing to this Java.exe along with the following parameters -Dsolr.solr.home=C:/solr -jar start.jar
You can also run C:\solr\java.exe -Dsolr.solr.home=C:/solr -jar C:/solr/start.jar from the command line without installing the service as a test which works fine.
If I leave Java.exe in the System32 folder though, things will not work and I get a java.lang.ClassNotFoundException for org.mortbay.xml.XmlConfiguration.
I can of course run C:\solr\java -Dsolr.solr.home=C:/solr -jar C:/solr/start.jar as well since Java is in my PATH.
If seems like I need an additional classpath option or something but I don't know?

I ended up using the following in the arguments for NSSM: -Dsolr.solr.home=C:/solr/ -Djetty.home=C:/solr/ -Djetty.logs=C:/solr/logs/ -cp C:/solr/lib/*.jar;C:/solr/start.jar -jar C:/solr/start.jar

Related

JAR is executed with terminal but not with direct clicking

I have tried the following:
in terminal it works
In Intellij it works
I have tried to launch it with javaw.exe but nothing changes
Are there any other options?
This looks like an OS problem that an application building one -- because you said that it works in your IDE and terminal.
Make sure that you installed Java properly in your machine.
In Windows/MacOs, after installing Java, the *.jar files are automatically associated with the java -jar command and makes it runnable via double-click.
In linux, this varies on the flavour or DE you are using. But there's probably a utility in your OS to open *.jar files using java -jar command.

Adding Java jar as Ubuntu service

I am trying to add my java jar application to Ubuntu as service so that when the Ubuntu server is restarted I dont need to manually run the jar command to run my application. At present I have to run this cmd on the terminal
java -jar myapp.jar -conf conf.json.
I came accross this link which would have solved my problem but for some reason the service is not running when i run the service as described in that website.
http://www.jcgonzalez.com/ubuntu-16-java-service-wrapper-example
Can someone please help me!!
I think your bash script should have "nohup" like this:
nohup java -jar myapp.jar -conf conf.json &

java missing class when supervisor running process but not when running as www-data user

I've made my first clojure app and I've built it with leiningen by running lein ring uberjar. I can run this on my dev machine (fedora 23) and I can run this on my ubuntu production machine java -jar tomahawk.jar. I've followed the digital ocean tutorial here that describes how to set up the environment. My supervisor conf is the following:
[program:tomahawk]
environment=TOMAHAWK_DB=$TOMAHAWK_DB
command=/usr/lib/jvm/java-1.7.0-openjdk-amd64/bin/java -jar tomahawk.jar
logfile=/tmp/supervisord.log
directory=/var/www/tomahawk/app
user=www-data
autostart=true
autorestart=true
startretries=3
redirect_stderr=true
stdout_logfile=/var/www/logs/tomahawk.app.log
However, when using this through nginx, i get the error
2016-03-19 23:34:08.594:WARN:oejs.AbstractHttpConnection:/
java.sql.SQLException: No suitable driver found for jdbc:sqlserver:$
at java.sql.DriverManager.getConnection(DriverManager.java:596)
at java.sql.DriverManager.getConnection(DriverManager.java:187)
at clojure.java.jdbc$get_connection.invoke(jdbc.clj:255)
This comes from the com.microsoft.sqldbc4.jar file. However, I can run this standalone jar file, as well as I can run sudo -u www-data env TOMAHAWK_DB=$TOMAHAWK_DB java -jar tomahawk.jar just fine. Also, while this is running, I can hit it through the nginx reverse proxy.
I've searched around and found an unanswered email on the supervisor mailing list from 2011. Why can I only sometimes see the missing jar file?
I've tried putting it inside of the /usr/lib/jvm/.../lib/ext location for my jvm, bundled inside of the jar file, running from Tomcat, etc. I've made an upstart script as well with identical results as well. I am not sure what other paths I can try and was wondering if anyone had any insights.

How to find where Tomcat is install/running from when it is not installed as a service

I'm trying to determine the Tomcat install directory when it is started from startup.bat in Windows.
It is easy enough to determine where tomcat7.exe is running when Tomcat is running as a service, but I'm not sure how to do it when it's started with the script. I know java is running when Tomcat is started from the script, but the executable path is for the java jre. Is there something I can do to find where catalina is running based on java?
Assuming you know the location of startup.bat, then just go two folders above and you're done.
Assuming you only have a shortcut to this file, then you would need to retrieve a list of processes explaining the application and the location of the files they're using, similar like ps aux command from Unix based OSes. Fortunately, Windows have such thing as well. From this great Q/A: Is there a command in Windows like ps -aux in UNIX?, more specifically, this answer, the way to find the location of tomcat in Windows is to execute the wmic application (through CMD if you want) and write process command, this will provide a list of the current applications running and their parameters. For example, I initialized Tomcat from startup.bat file and got this result using the commands above (single line):
java.exe "C:\Program Files\Java\jdk1.7.0_40\bin\java" -Djava.util.logging.config.file="<TOMCAT_HOME>\conf\logging.properties" -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs="<TOMCAT_HOME>\endorsed" -classpath "<TOMCAT_HOME>\bin\bootstrap.jar;<TOMCAT_HOME>\bin\tomcat-juli.jar" -Dcatalina.base="<TOMCAT_HOME>" -Dcatalina.home="<TOMCAT_HOME>" -Djava.io.tmpdir="<TOMCAT_HOME>\temp" org.apache.catalina.startup.Bootstrap start
Here's the same result but splitted in several lines to ease readability:
java.exe "C:\Program Files\Java\jdk1.7.0_40\bin\java"
-Djava.util.logging.config.file="<TOMCAT_HOME>\conf\logging.properties"
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Djava.endorsed.dirs="<TOMCAT_HOME>\endorsed"
-classpath "<TOMCAT_HOME>\bin\bootstrap.jar;<TOMCAT_HOME>\bin\tomcat-juli.jar"
-Dcatalina.base="<TOMCAT_HOME>"
-Dcatalina.home="<TOMCAT_HOME>"
-Djava.io.tmpdir="<TOMCAT_HOME>\temp"
org.apache.catalina.startup.Bootstrap start
Note: I've replaced the real path by <TOMCAT_HOME> in the results from above.
TL;DR do this:
Open cmd
Execute wmic
Execute process
Wait few secs and search java.exe and the arguments containing Tomcat jars.
Since you explicitly mentioned *.bat and Windows here is your answer.
1.Most tomcat application comes as a zip instead as msi/exe . The place where you extract is actually its locations . You start the application by clicking startup.bat file
2.Open the bat file with notepad . You will also find the relative path of the application.
3.Look for the path variables .
Hope this information helps

Using Tomcat 7 on Ubuntu 12.10 --- How To?

I am a newbie to Ubuntu 12.10 and moved to it from Windows.
In Windows I have configured the environment variable to include servlet-api.jar in the CLASSPATH variable so I do not have to type -cp <path to servlet-api.jar> every time I compile.
For normal Java programs, I have set the JAVA_HOME using:
export JAVA_HOME="/usr/lib/jvm/java-7-openjdk-i386" >> ~/.bashrc
With that solved, I need to set the CLASSPATH but do not know how to.
Please help on that!
Also I read on some forums that I should change the CLASSPATH manually each time I compile because changing the CLASSPATH may upset other applications.
Next, I tried this command to start Tomcat
service tomcat7 start but I got an error :
You need root privileges to run this script I do not know why. Help me solve that!
And if within the scope, please tell me how the directory structure of tomcat in Windows differs from that in Ubuntu.
Misc
I used sudo apt-get install tomcat7 to get Tomcat 7.
You don't say whether you're using an Ubuntu Tomcat package or a standalone Tomcat installation.
For a standalone Tomcat, you will be starting and stopping it using the scripts in its bin directory: startup.sh and shutdown.sh. In that case, Tomcat will use the environment variable values set at the time of invocation.
When doing this, you can set the environment variables prior to running these commands.
The same is true for the Tomcat 6 or Tomcat 7 that Ubuntu distributes as packages.
These neatly separate the $CATALINA_HOME directory (where the Tomcat 7 distribution is supposed to be) from the $CATALINA_BASE directory (where all of the changes and additions for a particular Tomcat instance are supposed to be. For the tomcat7 package, the first directory is /usr/share/tomcat7, while the second is /var/lib/tomcat7.
You can find startup.sh and shutdown.sh in /usr/share/tomcat7/bin and of course you can use them.
However, if you use the Tomcat provided with Ubuntu, you're probably going to want to run it just like any other standard system service, and the packages support this: e.g. in the case of tomcat7, you can just use
sudo service tomcat7 status
sudo service tomcat7 start
sudo service tomcat7 stop
sudo service tomcat7 restart
just like you can for any system service, and it uses the same mechanism as other system services do:
the shell script /etc/init.d/tomcat7 is used to start and stop Tomcat 7
/etc/default/tomcat7 is its configuration file, allowing a few parameters to be set
Using this method, you cannot specify additional environment variables for Tomcat to use by setting them in your shell or in /etc/default/tomcat7; they will not be passed to Tomcat.
However, there is a second method to set environment variables: if you set them in the shell script /var/lib/tomcat7/bin/setenv.sh (or, if you must, /usr/share/tomcat7/bin/setenv.sh), they will be picked up and passed to Tomcat. This method always works.
Finally, Tomcat offers finer control than just using a $CLASSPATH when it comes to specifying additional classes or JARs to be loaded on startup: in its conf/catalina.properties configuration file, you can set the common.loader, server.loader and shared.loader to a list of directories and/or JAR files to be loaded in additional to the standard ones.
All it means is that you should do that as a superuser - which translates to administrator in windows so you should try something like sudo service tomcat7 start
Try export CLASSPATH=/usr/share/tomcat7/lib/servlet-api.jar:/usr/share/tomcat7/lib/jsp-api.jar - This will depend on where your tomcat installation in located.
You can get more here
Cheers

Categories

Resources