1. Download assumervice
Http://javaservice.objectweb.org/
Obtain the zip compression version of Windows. The file name is in the form of "assumervice-x.xx.zip". In the file name, "x.xx" indicates the correct number, and" assumervice-2.0.10.zip "indicates the current version. Use the latest version.
2 Installation
Decompress assumervice-2.0.10.zip to the C:/assumervice directory. (In fact, any directory can be used)
3. Write Java classes
Import java. Io .*;
Import java. Text .*;
Import java. util .*;
Public class test
{
Public static void main (string [] ARGs) throws exception
{
Printwriter out = new printwriter (New filewriter ("D: // javatest // test. log", true), true );
Simpledateformat df = new simpledateformat ("yyyy-mm-dd hh: mm: SS ");
Out. println ("service started at:" + DF. Format (new date ()));
While (true)
{
Out. println ("the current time is:" + DF. Format (new date ()));
Thread. Sleep (1000*5 );
}
}
}
Save it as any directory, such as "D:/javatest/test. Java" and compile it as test. Class;
4. Go to the C:/assumervice directory and run the following command:
Assumervice.exe-install myservice "% java_home %"/JRE/bin/Server/JVM. DLL-djava. class. path = "% java_home %"/lib/tools. jar; D:/javatest-start test
The parameter after the-install switch is the name of the service to be added; the parameter after the-start switch is the name of the Java class to be started; here-djava. class. d:/javatest In the parameter after path is my test. class path. You should add your classpath in the actual application.
After running, the console displays "The myservice automatic service was successfully installed", indicating that the installation is successful.
Notes:
(1) % java_home % is the JDK directory. If you have not set it, use the absolute address of JDK here;
(2)-djava. Class. Path is required because the classpath variable of the system cannot be accessed when the service is started. It must be shown here;
(3) After the service is successfully added, it is the automatic start type. If you need to change it, you must modify it in the Service Manager (services. MSC.
5 test:
Run Net start myservice to start the service;
Check the D:/javatest/test. log file. The data is constantly updated;
Run net stop myservice to close the service;
6. Customization
Add classpath to installjboss. bat
Set xmlbeans_path = % oe_home %/lib/xmlbeans/jsr173_1.0_api.jar; % oe_home %/lib/xmlbeans/resolver. jar; % oe_home %/lib/xmlbeans/xbean. jar; % oe_home %/lib/xmlbeans/xbean_xpath.jar; % oe_home %/lib/xmlbeans/xmlpublic. jar
Set oe_class_path = % oe_home %/conf; % oe_home %/lib/pojo. jar; % oe_home %/lib/hibernate-mapping-1.0.jar; % oe_home %/lib/resource-model-1.0.jar; % oe_home %/lib/antlr-2.7.6.jar; % oe_home %/lib/jta-1.0.1B.jar; % oe_home %/lib/commons-collections-2.1.1.jar; % oe_home %/lib/commons-logging-1.0.4.jar; % oe_home %/lib/log4j. jar; % oe_home %/lib/dom4j-1.6.1.jar; % oe_home %/lib/jaxen-1.1.jar; % oe_home %/lib/icu4j-2.6.1.jar
Add classpath
Set jboss_classpath = % oe_class_path %; % xmlbeans_path %; % jboss_classpath %
Call (Add the specified server IP address>-Params-B 0.0.0.0)
% 2/bin/jbossservice.exe-install JBoss % 1/JRE/bin/% 3/JVM. DLL-djava. class. path = % 1/lib/tools. jar; % 2/bin/run. jar; % jboss_classpath %-start Org. JBoss. main-Params-B 0.0.0.0-Stop Org. JBoss. main-method systemexit-current % 2/bin % 4-overwrite
Set memory
Set maxmemory = 256
Set minmemory = 128
Set java_opts = % java_opts %-XMS % minmemory % m-xmx % maxmemory % m
REM with sun JVMs reduce the RMI GCs to once per hour
Set java_opts = % java_opts %-dsun. RMI. DGC. Client. gcinterval = 3600000-dsun. RMI. DGC. server. gcinterval = 3600000
"% Jbossexe %"-install "% svcname %" "% jvmdll %"-djava. class. path = "% jboss_classpath %" % java_opts %-start Org. JBoss. main-Stop Org. JBoss. main-method systemexit-out "% jboss_home %/bin/stdout. log "-Err" % jboss_home %/bin/stderr. log "-current" % jboss_home %/bin "-auto-overwrite