.jar as windows Service, use config file - Advanced Installer Community

We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

popesko
Posts: 3
Joined: Tue Mar 29, 2011 10:00 pm

.jar as windows Service, use config file

Hi all,

I have a java project, compiled and packed as .jar file.
I am using the app ok with the .config file where i have stored some info. If running in command prompt using the java -jar command, it uses correctly the .config file.
Testing as a service, i have done some tests on intalation, and even using the .config file in the package installed, the service is not starting conveniently.

Can you please help me on this? How i use the same .config file with the jar as a windows service?

Thnks and Regards,

Tiago
popesko
Posts: 3
Joined: Tue Mar 29, 2011 10:00 pm

Re: .jar as windows Service, use config file

Hi again,

I confirm that the JAR file as a service, if not using the '.config' file, is working fine. But if in the JAR java code, i want read info from file (even installing the config file automatically using the .msi) the service cannot start as it should.
Note that in i run only the JAR directly from the command prompt, its working with the .config file.

Thnks,

Tiago
kkrzyzak
Posts: 47
Joined: Wed Oct 13, 2010 2:10 pm

Re: .jar as windows Service, use config file

Hi Tiago,

Tell me how you get path to this config file?
If you install jar as service it's classpath is e.g. for winxp C:\windows\system32 so if you are using getClassPath() method to get your config it's worng.
You should use ProtectionDomain class - look at Java API for more info.

Best,
Karol.
popesko
Posts: 3
Joined: Tue Mar 29, 2011 10:00 pm

Re: .jar as windows Service, use config file

Hi Karol, thnks for reply.

check plse part of the java code i am using in the main method:

String aFile="./U-MADDesktopConnector.properties";
if(args.length > 0){
try{
port = Integer.parseInt(args[0]);
if(port < 1024 || port >= 0x10000)
{
System.out.println("Port must between 1024 and 65535");
return;
}
}
catch(NumberFormatException numberformatexception) { }
}else{
try {
//use buffering, reading one line at a time
//FileReader always assumes default encoding is OK!
BufferedReader input = new BufferedReader(new FileReader(aFile));
try {
String line = null;
line = input.readLine();
line = line.substring(line.indexOf('=')+1);
port=Integer.parseInt(line);

line = input.readLine();
hostname = line.substring(line.indexOf('=')+1);
//actually we don't do anything with hostname!!
}
finally {
input.close();
}
}
catch (IOException ex){
ex.printStackTrace();
}

In the JAR i include the classpath file and an INI file that have inside:

[Java Runtime Environment]
Maximum Version=any
Minimum Version=any
Main Class=umad.ServerMain
[Product Information]
Product Code={316CE0BE-F749-41C0-89F0-F39BCB78C0AE}
Product Name=U-MAD Desktop Connector
Upgrade Code={F6CC4EAD-25AB-4B19-8820-7902FA25E103}
[Application]
Application Type=service
[Class Path]
Class Path=C:\Program Files\U-MAD\U-MAD Desktop Connector\U-MADDesktopConnector.jar;


so, I am trying to use the config file like this, and it works if i call from command prompt the JAR file.

Thnks

Tiago
mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: .jar as windows Service, use config file

Hi Tiago and welcome to the Advanced Installer Forums,

It is usually not recommended to depend on the current directory. However, to avoid changing your code you could try to set your java product with "Set product folder as current"( java product -> Settings tab -> Application group ).

Best,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”