Discussion:
[DAEMON] procrun - java Property File
Andreas Mielke
2011-01-16 12:19:06 UTC
Permalink
I use Apache Common Daemon to install a java application as a windows service. The problem is i have a java properties file to setup few parameters and i don't know how to describe the location of the property file in the command line. My installation of the service is like

prunsrv //IS//TestService --DisplayName="Test Service" --Install=prunsrv.exe --Jvm=auto --StartMode=jvm --StopMode=jvm --StartClass=org.apache.SomeStartClass.

Andreas
Konstantin Kolinko
2011-01-16 13:27:56 UTC
Permalink
Post by Andreas Mielke
I use Apache Common Daemon to install a java application as a windows service. The problem is i have a java properties file to setup few parameters and i don't know how to describe the location of the property file in the command line. My installation of the service is like
prunsrv //IS//TestService --DisplayName="Test Service" --Install=prunsrv.exe --Jvm=auto --StartMode=jvm --StopMode=jvm --StartClass=org.apache.SomeStartClass.
If you want to pass it as a system property, use "JvmOptions" [1] to
specify -D.

Is it what you are asking? If you were running your app with
java(w).exe, what would be your command line?

[1] http://commons.apache.org/daemon/procrun.html

Best regards,
Konstantin Kolinko
Juan Pablo Pizarro
2011-01-16 19:37:11 UTC
Permalink
Andreas, you can use a resource bundle to obtain the .properties from the
jar.. i mean, you put the .properties into the file and you can read from
it.

I posted some classes to do that some months ago.

Regards.

JP
Post by Andreas Mielke
Post by Andreas Mielke
I use Apache Common Daemon to install a java application as a windows
service. The problem is i have a java properties file to setup few
parameters and i don't know how to describe the location of the property
file in the command line. My installation of the service is like
Post by Andreas Mielke
prunsrv //IS//TestService --DisplayName="Test Service"
--Install=prunsrv.exe --Jvm=auto --StartMode=jvm --StopMode=jvm
--StartClass=org.apache.SomeStartClass.
If you want to pass it as a system property, use "JvmOptions" [1] to
specify -D.
Is it what you are asking? If you were running your app with
java(w).exe, what would be your command line?
[1] http://commons.apache.org/daemon/procrun.html
Best regards,
Konstantin Kolinko
---------------------------------------------------------------------
Andreas Mielke
2011-01-16 19:57:15 UTC
Permalink
Hello JP,

Please write me a example?

Andreas
Post by Juan Pablo Pizarro
Andreas, you can use a resource bundle to obtain the .properties from the
jar.. i mean, you put the .properties into the file and you can read from
it.
I posted some classes to do that some months ago.
Regards.
JP
Post by Andreas Mielke
Post by Andreas Mielke
I use Apache Common Daemon to install a java application as a windows
service. The problem is i have a java properties file to setup few
parameters and i don't know how to describe the location of the property
file in the command line. My installation of the service is like
Post by Andreas Mielke
prunsrv //IS//TestService --DisplayName="Test Service"
--Install=prunsrv.exe --Jvm=auto --StartMode=jvm --StopMode=jvm
--StartClass=org.apache.SomeStartClass.
If you want to pass it as a system property, use "JvmOptions" [1] to
specify -D.
Is it what you are asking? If you were running your app with
java(w).exe, what would be your command line?
[1] http://commons.apache.org/daemon/procrun.html
Best regards,
Konstantin Kolinko
---------------------------------------------------------------------
Juan Pablo Pizarro
2011-01-16 20:24:21 UTC
Permalink
Into the zip you will find two classes. This was my post:

I attached two classes to get properties from a jar. You can modify its to
get other kind of files (I did it).
Finally, you can get content from the package and file into the jar.

In the properties case, you can get a property with something like that:

private static final String LDAP_CASA =
PropertyReaderHelper.getProperty("PROVIDER_URL_CASA");
private static final String CASA_CONTEXT_SEARCH_1 =
PropertyReaderHelper.getProperty("CONTEXT_SEARCH_CASA_1");
private static final String CASA_CONTEXT_SEARCH_2 =
PropertyReaderHelper.getProperty("CONTEXT_SEARCH_CASA_2");
private static final String CASA_PRINCIPAL =
PropertyReaderHelper.getProperty("PRINCIAL_CASA");
private static final String CASA_CREDENTIALS =
PropertyReaderHelper.getProperty("CREDENTIALS_CASA");

I hope it helps you.

Regards,

JP
Post by Andreas Mielke
Hello JP,
Please write me a example?
Andreas
Am 16.01.2011 um 20:37 schrieb Juan Pablo Pizarro <
Post by Juan Pablo Pizarro
Andreas, you can use a resource bundle to obtain the .properties from the
jar.. i mean, you put the .properties into the file and you can read from
it.
I posted some classes to do that some months ago.
Regards.
JP
Post by Andreas Mielke
Post by Andreas Mielke
I use Apache Common Daemon to install a java application as a windows
service. The problem is i have a java properties file to setup few
parameters and i don't know how to describe the location of the property
file in the command line. My installation of the service is like
Post by Andreas Mielke
prunsrv //IS//TestService --DisplayName="Test Service"
--Install=prunsrv.exe --Jvm=auto --StartMode=jvm --StopMode=jvm
--StartClass=org.apache.SomeStartClass.
If you want to pass it as a system property, use "JvmOptions" [1] to
specify -D.
Is it what you are asking? If you were running your app with
java(w).exe, what would be your command line?
[1] http://commons.apache.org/daemon/procrun.html
Best regards,
Konstantin Kolinko
---------------------------------------------------------------------
---------------------------------------------------------------------
Andreas Mielke
2011-01-17 07:54:58 UTC
Permalink
Hello JP,

I look at the files and the loading of the properties files is like me. My
problem is to tell the Apache Common Daemon where is my property file.

@ Konstantin I try the JvmOption like prunsrv //IS --Description="DMSImport"
--DisplayName="startImport" --Startup=auto --Type=interactiv
--Install=java.exe --Jvm=auto --StartMode=Java --StopMode=Java ++JvmOptions
-D=C:\Programme\DMS_ImageBrowser\DMSWrapper-binary-1.2\log4j.properties;
-D=C:\Programme\DMS_ImageBrowser\DMSWrapper-binary-1.2\DMSWrapper.properties;


But I have a FileNotFoundException.

Of Course I try ++JvmOptions
-D="C:\Programme\DMS_ImageBrowser\DMSWrapper-binary-1.2\log4j.properties;C:\Programme\DMS_ImageBrowser\DMSWrapper-binary-1.2\DMSWrapper.properties;"


But the in this case i have a ClassNotFoundException.

One point the Javaapplication is not writen by me. I have to run the program
only as awindows service.

I need a idea/Examples for the Problem.

Regards Andreas
Post by Juan Pablo Pizarro
I attached two classes to get properties from a jar. You can modify its to
get other kind of files (I did it).
Finally, you can get content from the package and file into the jar.
private static final String LDAP_CASA =
PropertyReaderHelper.getProperty("PROVIDER_URL_CASA");
private static final String CASA_CONTEXT_SEARCH_1 =
PropertyReaderHelper.getProperty("CONTEXT_SEARCH_CASA_1");
private static final String CASA_CONTEXT_SEARCH_2 =
PropertyReaderHelper.getProperty("CONTEXT_SEARCH_CASA_2");
private static final String CASA_PRINCIPAL =
PropertyReaderHelper.getProperty("PRINCIAL_CASA");
private static final String CASA_CREDENTIALS =
PropertyReaderHelper.getProperty("CREDENTIALS_CASA");
I hope it helps you.
Regards,
JP
Post by Andreas Mielke
Hello JP,
Please write me a example?
Andreas
Am 16.01.2011 um 20:37 schrieb Juan Pablo Pizarro <
Post by Juan Pablo Pizarro
Andreas, you can use a resource bundle to obtain the .properties from
the
Post by Juan Pablo Pizarro
jar.. i mean, you put the .properties into the file and you can read
from
Post by Juan Pablo Pizarro
it.
I posted some classes to do that some months ago.
Regards.
JP
Post by Andreas Mielke
Post by Andreas Mielke
I use Apache Common Daemon to install a java application as a windows
service. The problem is i have a java properties file to setup few
parameters and i don't know how to describe the location of the
property
Post by Juan Pablo Pizarro
Post by Andreas Mielke
file in the command line. My installation of the service is like
Post by Andreas Mielke
prunsrv //IS//TestService --DisplayName="Test Service"
--Install=prunsrv.exe --Jvm=auto --StartMode=jvm --StopMode=jvm
--StartClass=org.apache.SomeStartClass.
If you want to pass it as a system property, use "JvmOptions" [1] to
specify -D.
Is it what you are asking? If you were running your app with
java(w).exe, what would be your command line?
[1] http://commons.apache.org/daemon/procrun.html
Best regards,
Konstantin Kolinko
---------------------------------------------------------------------
---------------------------------------------------------------------
---------------------------------------------------------------------
Konstantin Kolinko
2011-01-17 09:56:18 UTC
Permalink
Post by Andreas Mielke
Hello JP,
I look at the files and the loading of the properties files is like me. My
problem is to tell the Apache Common Daemon where is my property file.
@ Konstantin I try the JvmOption like prunsrv //IS --Description="DMSImport"
--DisplayName="startImport" --Startup=auto --Type=interactiv
--Install=java.exe --Jvm=auto --StartMode=Java --StopMode=Java ++JvmOptions
You are not specifying "--Classpath". How java is supposed to find your program?
Post by Andreas Mielke
-D=C:\Programme\DMS_ImageBrowser\DMSWrapper-binary-1.2\log4j.properties;
-D=C:\Programme\DMS_ImageBrowser\DMSWrapper-binary-1.2\DMSWrapper.properties;
But I have a FileNotFoundException.
Of Course I try ++JvmOptions
-D="C:\Programme\DMS_ImageBrowser\DMSWrapper-binary-1.2\log4j.properties;C:\Programme\DMS_ImageBrowser\DMSWrapper-binary-1.2\DMSWrapper.properties;"
That quotes would be

--JvmOptions "-D=C:\Programme\DMS_ImageBrowser\DMSWrapper-binary-1.2\log4j.properties#-D=C:\Programme\DMS_ImageBrowser\DMSWrapper-binary-1.2\DMSWrapper.properties"

but anyway, your "-D" makes no sense: you are not specifying the name
of a system property.
Post by Andreas Mielke
One point the Javaapplication is not writen by me.
Is "DMSWrapper" your program, or it is a part of the "not writen by
me" application?

How is that application run when you do not use your wrapper? -- Does
it load those properties files? How does it find them? Ask the
Post by Andreas Mielke
If you were running your app with java(w).exe, what would be your command line?
The log4j.properties file is usually placed into a directory that is
added to the ClassPath (and thus there is no need to specify its
location explicitly).


Best regards,
Konstantin Kolinko
Andreas Mielke
2011-01-17 10:33:23 UTC
Permalink
Post by Andreas Mielke
Post by Andreas Mielke
Hello JP,
I look at the files and the loading of the properties files is like me.
My
Post by Andreas Mielke
problem is to tell the Apache Common Daemon where is my property file.
@ Konstantin I try the JvmOption like prunsrv //IS
--Description="DMSImport"
Post by Andreas Mielke
--DisplayName="startImport" --Startup=auto --Type=interactiv
--Install=java.exe --Jvm=auto --StartMode=Java --StopMode=Java
++JvmOptions
You are not specifying "--Classpath". How java is supposed to find your program?
I don't posted the --Classpath, sorry. The complete command is:

prunsrv //IS --Description="DMSImport" --DisplayName="startImport"
--Startup=auto --Type=interactiv --Install=java.exe --Jvm=auto
--StartMode=Java --StopMode=Java --StartClass=dmswrapper.DMSImporter
--Classpath=%CLASSPATH%;C:\Programme\DMS_ImageBrowser\DMSWrapper-binary-1.2\DMSWrapper.jar;C:\Programme\DMS_ImageBrowser\DMSWrapper-binary-1.2\log4j-1.2.15.jar;C:\Programme\DMS_ImageBrowser\DMSWrapper-binary-1.2\log4j-extensions.jar;C:\Programme\DMS_ImageBrowser\DMSWrapper-binary-1.2\commons-codec-1.3.jar;C:\Programme\DMS_ImageBrowser\DMSWrapper-binary-1.2\commons-httpclient-3.1.jar;C:\Programme\DMS_ImageBrowser\DMSWrapper-binary-1.2\commons-logging-1.1.1.jar;C:\Programme\DMS_ImageBrowser\DMSWrapper-binary-1.2\commons-net-2.0.jar;C:\Programme\DMS_ImageBrowser\DMSWrapper-binary-1.2\EloixClient.jar;
++JvmOptions
-D=C:\Programme\DMS_ImageBrowser\DMSWrapper-binary-1.2\DMSWrapper.properties;
--LogPath="C:\Programme\commons-daemon-1.0.5-bin-windows\logs"
--LogLevel=Debug --StdOutput=auto --ServiceUser=********
--ServicePassword=*******(private ;-) )
Post by Andreas Mielke
Post by Andreas Mielke
-D=C:\Programme\DMS_ImageBrowser\DMSWrapper-binary-1.2\log4j.properties;
-D=C:\Programme\DMS_ImageBrowser\DMSWrapper-binary-1.2\DMSWrapper.properties;
Post by Andreas Mielke
But I have a FileNotFoundException.
Of Course I try ++JvmOptions
-D="C:\Programme\DMS_ImageBrowser\DMSWrapper-binary-1.2\log4j.properties;C:\Programme\DMS_ImageBrowser\DMSWrapper-binary-1.2\DMSWrapper.properties;"
That quotes would be
--JvmOptions
"-D=C:\Programme\DMS_ImageBrowser\DMSWrapper-binary-1.2\log4j.properties#-D=C:\Programme\DMS_ImageBrowser\DMSWrapper-binary-1.2\DMSWrapper.properties"
but anyway, your "-D" makes no sense: you are not specifying the name
of a system property.
Post by Andreas Mielke
One point the Javaapplication is not writen by me.
Is "DMSWrapper" your program, or it is a part of the "not writen by
me" application?
This is the foreign program, I know the principal functions but no lines of
code.
Post by Andreas Mielke
How is that application run when you do not use your wrapper?
I start a cmd-file (), one command line starts and the properties are load
automatical without problems.
Post by Andreas Mielke
-- Does
it load those properties files? How does it find them? Ask the
Post by Andreas Mielke
If you were running your app with java(w).exe, what would be your
command line?
yes. A CMD- File with the command java -cp ... .
Post by Andreas Mielke
The log4j.properties file is usually placed into a directory that is
added to the ClassPath (and thus there is no need to specify its
location explicitly).
Best regards,
Konstantin Kolinko
---------------------------------------------------------------------
Adam Mlodzinski
2011-01-18 00:35:01 UTC
Permalink
Post by Andreas Mielke
My problem is to tell the Apache Common Daemon where is my property file.
No, this is not your problem. The Commons Daemon does not care about your property file. The Java program that the Commons Daemon will run *does* care.
Post by Andreas Mielke
prunsrv //IS --Description="DMSImport" --DisplayName="startImport"
--Startup=auto --Type=interactiv --Install=java.exe --Jvm=auto
--StartMode=Java --StopMode=Java --StartClass=dmswrapper.DMSImporter
--Classpath=%CLASSPATH%;C:\Programme\DMS_ImageBrowser\DMSWrapper-binary-
1.2\DMSWrapper.jar;C:\Programme\DMS_ImageBrowser\DMSWrapper-binary-1.2\log4j-
1.2.15.jar;C:\Programme\DMS_ImageBrowser\DMSWrapper-binary-1.2\log4j-
extensions.jar;C:\Programme\DMS_ImageBrowser\DMSWrapper-binary-1.2\commons-codec-
1.3.jar;C:\Programme\DMS_ImageBrowser\DMSWrapper-binary-1.2\commons-httpclient-
3.1.jar;C:\Programme\DMS_ImageBrowser\DMSWrapper-binary-1.2\commons-logging-
1.1.1.jar;C:\Programme\DMS_ImageBrowser\DMSWrapper-binary-1.2\commons-net-
2.0.jar;C:\Programme\DMS_ImageBrowser\DMSWrapper-binary-1.2\EloixClient.jar;
++JvmOptions
-D=C:\Programme\DMS_ImageBrowser\DMSWrapper-binary-1.2\DMSWrapper.properties;
--LogPath="C:\Programme\commons-daemon-1.0.5-bin-windows\logs"
--LogLevel=Debug --StdOutput=auto --ServiceUser=********
--ServicePassword=*******(private ;-) )
This is the foreign program, I know the principal functions but no lines of
code.
This is not a problem either. If you do not know how to run a Java program in general, that could be a problem.
Post by Andreas Mielke
How is that application run when you do not use your wrapper?
yes. A CMD- File with the command java -cp ... .
Ahh - here is your answer. You must translate every option of the 'java -cp ...' which is produced by the CMD-File into options that the Commons Daemon installer understands.
Try adding an "echo on" just before the 'java -cp ...' command inside the CMD-File. When you run it, you will see the entire java command that is launched, along with every option that you must translate.
You will also need to add some new information to describe the service itself - the service name, description, log files, service user, etc. But, focus on the Java-specific pieces first.


For example, here is a result of putting an 'echo on' inside catalina.bat (for Tomcat 5.5.31):

Mon 19:17:06>"c:\jdk1.6.0_12\bin\java" -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file="C:\work\appservers\tomcat\5.5\apache-tomcat-5.5.31\conf\logging.properties" -Djava.endorsed.dirs="C:\work\appservers\tomcat\5.5\apache-tomcat-5.5.31\common\endorsed" -classpath "C:\work\appservers\tomcat\5.5\apache-tomcat-5.5.31\bin\bootstrap.jar" -Dcatalina.base="C:\work\appservers\tomcat\5.5\apache-tomcat-5.5.31" -Dcatalina.home="C:\work\appservers\tomcat\5.5\apache-tomcat-5.5.31" -Djava.io.tmpdir="C:\work\appservers\tomcat\5.5\apache-tomcat-5.5.31\temp" org.apache.catalina.startup.Bootstrap start

To make this command run as a Windows Service started by Apache Commons Daemon, you could use the following command to install it (to use prunsrv.exe + jvm.dll):


prunsrv //IS ^
--Jvm=c:\jdk1.6.0_12\jre\bin\server.jvm.dll ^
++JvmOptions=-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager ^
++JvmOptions=-Djava.util.logging.config.file="C:\work\appservers\tomcat\5.5\apache-tomcat-5.5.31\conf\logging.properties"^
++JvmOptions=-Djava.endorsed.dirs="C:\work\appservers\tomcat\5.5\apache-tomcat-5.5.31\common\endorsed" ^
--Classpath="C:\work\appservers\tomcat\5.5\apache-tomcat-5.5.31\bin\bootstrap.jar" ^
++JvmOptions=-Dcatalina.base="C:\work\appservers\tomcat\5.5\apache-tomcat-5.5.31" ^
++JvmOptions=-Dcatalina.home="C:\work\appservers\tomcat\5.5\apache-tomcat-5.5.31" ^
++JvmOptions=-Djava.io.tmpdir="C:\work\appservers\tomcat\5.5\apache-tomcat-5.5.31\temp" ^
--StartMode=jvm ^
--StartClass=org.apache.catalina.startup.Bootstrap ^
++StartParams start


Next, add options for logging and for stopping the service.


To be more precise (ie - use the JDKs 'default' jvm, as the original command does), you would want to use a start mode of Java:

prunsrv //IS ^
--JavaHome=c:\jdk1.6.0_12 ^
--StartMode=Java ^

That would launch c:\jdk1.6.0_12\bin\java.exe as a separate process.

Hopefully this helps.


--
Adam M.

Loading...