GVKun编程网logo

以编程方式将Tomcat的Java选项设置为Windows服务的方法(tomcat编译java文件)

20

对于以编程方式将Tomcat的Java选项设置为Windows服务的方法感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍tomcat编译java文件,并为您提供关于c#–以编程方式启用Windo

对于以编程方式将Tomcat的Java选项设置为Windows服务的方法感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍tomcat编译java文件,并为您提供关于c# – 以编程方式启用Windows服务、c# – 如何以编程方式将RadComboBox与数据源设置为AutomaticLoadOnDemand、java – 如何以编程方式将webservice发布到tomcat、java.lang.OutOfMemoryError:带有tomcat7 Windows服务的PermGen空间的有用信息。

本文目录一览:

以编程方式将Tomcat的Java选项设置为Windows服务的方法(tomcat编译java文件)

以编程方式将Tomcat的Java选项设置为Windows服务的方法(tomcat编译java文件)

我正在寻找一种以编程方式设置Tomcat 6.0 作为Windows服务运行的 Java选项的方法 当使用startup.bat和shutdown.bat ,可以在setenv.bat或catalina.bat文件中设置这些variables。 但是,对于作为Windows Service运行的Tomcat,必须在configuration实用程序的Java选项部分中手动设置这些选项。

有没有办法以编程方式设置这些选项?

背景:我正在尝试编写一个将我的应用程序部署到现有Tomcat 6.0服务器的安装程序。 我可以以编程方式执行其他任何操作,但我仍然需要让用户在这些设置中手动添加一些Java选项。 这并不理想,特别是因为这些选项是大小写和空白的。

Wix:将自定义操作中的文件复制到Programm目录(Windows 7)

如何确定是否使用Inno安装程序安装了特定的Windows Update软件包(KB * .msu)?

在Windows 7中使用Pyinstaller创build的exe在xp和linux中不起作用

什么是最清洁的方式来编程终止并重新启动explorer.exe?

从Windows服务调用MSIGetProductInfo返回垃圾值

使用NSIS复制一个目录。

ant独立软件包或其他安装程序(对于Java Web应用程序,Windows)

Linux / UNIX安装数据文件

如何让vcredist成为我的MSI安装程序的启动条件?

安装程序还是没有安装程序?

用于将Tomcat作为Windows服务运行的Tomcat6二进制文件具有一堆命令行参数 ,可能对您有所帮助。 我预见的唯一问题是很难(不可能?)检索当前的设置,以便您可以修改它们…

总结

以上是小编为你收集整理的以编程方式将Tomcat的Java选项设置为Windows服务的方法全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

c# – 以编程方式启用Windows服务

c# – 以编程方式启用Windows服务

我试图通过修改注册表中的值以编程方式启用 Windows服务,如下所示.价值确实在变化.但是,之后我无法启动该服务,因为Windows仍然将其视为已禁用.

public void EnabledTheService(string serviceName)
{
    try
    {
        RegistryKey key = Registry.LocalMachine
                                   .OpenSubKey(@"SYstem\CurrentControlSet\Services\"
                                                       + serviceName,true);
        key.SetValue("Start",2);                
    }
    catch (Exception ex)
    {
         Console.Write(ex.Message);
    }
}

public void StartService(string serviceName)
{
    ServiceController service = new ServiceController(serviceName);
    try
    {
        service.Start();
        service.WaitForStatus(ServiceControllerStatus.Running,new TimeSpan(0,20));
    }
    catch (Exception ex)
    {
        Console.Write(ex.Message);
    }
}

解决方法

有几种方法可以更改Windows服务的启动类型(请参阅 this question).如果我没记错,WMI方法在我测试时工作但不完全可靠,所以我使用了Windows API函数 ChangeServiceConfig.我从未尝试过注册表方法.我认为这将是三个选项中最不稳定的.

请注意,如果您想要“自动(延迟启动)”模式,则需要拨打ChangeServiceConfig2.

public void ChangeServiceStartType(string serviceName,ServiceStartupType startType)
{
    //Obtain a handle to the service control manager database
    IntPtr scmHandle = OpenSCManager(null,null,SC_MANAGER_CONNECT);
    if (scmHandle == IntPtr.Zero)
    {
        throw new Exception("Failed to obtain a handle to the service control manager database.");
    }

    //Obtain a handle to the specified windows service
    IntPtr serviceHandle = OpenService(scmHandle,serviceName,SERVICE_QUERY_CONfig | SERVICE_CHANGE_CONfig);
    if (serviceHandle == IntPtr.Zero)
    {
        throw new Exception($"Failed to obtain a handle to service '{serviceName}'.");
    }

    //Change the start mode
    bool changeServiceSuccess = ChangeServiceConfig(serviceHandle,SERVICE_NO_CHANGE,(uint)startType,IntPtr.Zero,null);
    if (!changeServiceSuccess)
    {
        string msg = $"Failed to update service configuration for service '{serviceName}'. ChangeServiceConfig returned error {Marshal.GetLastWin32Error()}.";
        throw new Exception(msg);
    }

    //Clean up
    if (scmHandle != IntPtr.Zero)
        CloseServiceHandle(scmHandle);
    if (serviceHandle != IntPtr.Zero)
        CloseServiceHandle(serviceHandle);
}

[DllImport("advapi32.dll",CharSet = CharSet.Auto,SetLastError = true)]
private static extern IntPtr OpenSCManager(string machineName,string databaseName,uint dwAccess);

[DllImport("advapi32.dll",SetLastError = true)]
private static extern IntPtr OpenService(IntPtr hSCManager,string lpServiceName,uint dwDesiredAccess);

[DllImport("advapi32.dll",SetLastError = true)]
private static extern bool ChangeServiceConfig(
    IntPtr hService,uint nServiceType,uint nStartType,uint nErrorControl,string lpBinaryPathName,string lpLoadOrderGroup,IntPtr lpdwTagId,[In] char[] lpDependencies,string lpServiceStartName,string lpPassword,string lpdisplayName);

[DllImport("advapi32.dll",EntryPoint = "CloseServiceHandle")]
private static extern int CloseServiceHandle(IntPtr hSCObject);

private const uint SC_MANAGER_CONNECT = 0x0001;
private const uint SERVICE_QUERY_CONfig = 0x00000001;
private const uint SERVICE_CHANGE_CONfig = 0x00000002;
private const uint SERVICE_NO_CHANGE = 0xFFFFFFFF;

public enum ServiceStartupType : uint
{
    /// <summary>
    /// A device driver started by the system loader. This value is valid only for driver services.
    /// </summary>
    BootStart = 0,/// <summary>
    /// A device driver started by the IoInitSystem function. This value is valid only for driver services.
    /// </summary>
    SystemStart = 1,/// <summary>
    /// A service started automatically by the service control manager during system startup.
    /// </summary>
    Automatic = 2,/// <summary>
    /// A service started by the service control manager when a process calls the StartService function.
    /// </summary>
    Manual = 3,/// <summary>
    /// A service that cannot be started. Attempts to start the service result in the error code ERROR_SERVICE_disABLED.
    /// </summary>
    disabled = 4
}

c# – 如何以编程方式将RadComboBox与数据源设置为AutomaticLoadOnDemand

c# – 如何以编程方式将RadComboBox与数据源设置为AutomaticLoadOnDemand

我正在使用RadComboBox.在我的代码中,我将选定的值设置为RadComboBox,如下所示:
public void RCB_PO_NUM_DataBound(object sender,EventArgs e)
        {

            var itemRCB_PO_NUM = RCB_PO_NUM.FindItemByText(stringPO_NUM);

            itemRCB_PO_NUM.Selected = true;
            itemRCB_PO_NUM.Value = stringPO_NUM;


        }

我从我的数据库中选择一个数字列表,并在RadComboBox中显示它们.所以我必须使用DataBound事件来获取数据.

这很好用,直到我将AutomaticLoadondemand属性设置为true.一旦我这样做,我使用AutomaticLoadondemand属性获得我想要的效果,然后失去将我的RadComboBox设置为选定值的能力.

我需要能够做到这两点,AutomaticLoadondemand真的有助于加载RadComboBox中的项目以加载非常快.代码不必在DataBound事件中.我真的不在乎它是什么事件,只要两个都工作.有些人可以告诉我用什么方法将AutomaticLoadondemand属性设置为true,或者我做错了什么?

解决方法

当您使用Loadondemand时,您的组合框不会被绑定,直到用户尝试展开它.所以你不能使用DataBound事件.

我不确定你的用例是什么.如果您只想向用户显示所选项目,则可以在Page_Load事件中尝试组合框的Text属性.

protected void Page_Load(object sender,EventArgs e)
{
    itemRCB_PO_NUM.Text = stringPO_NUM;
}

如果你真的需要选择项目,那么你可以添加单项服务器端(抱歉我现在无法测试)

protected void Page_Load(object sender,EventArgs e)
{
    itemRCB_PO_NUM.Items.Add(new RadComboBoxItem()
    {
        Value = stringPO_NUM,Text= stringPO_NUM,Selected = true
    })
}

编辑:
我做了一些research,似乎应该正确触发ItemDataBound事件:

Note: When you use the DataSourceID or DataSource properties to bind RadComboBox during automatic Load On Demand the ItemDataBound event fires normally,which means that you can use it to change the Item’s Text and Value properties as well as modify its Attributes collection based on the DataItem,etc.

所以你可以尝试使用它:

protected void RadComboBox1_ItemDataBound(object o,RadComboBoxItemEventArgs e)
{ 
    DaTarowView dataSourceRow = (DaTarowView) e.Item.DataItem;  
    if(e.Item.Text == stringPO_NUM)
    {
        e.Item.Selected = true;
        e.Item.Value = stringPO_NUM;
    }
}

但是对我来说可疑的是,在评论中提供的屏幕上我可以看到你的字符串stringPO_NUM具有空值.我认为这可能是GetItemByText没有向您返回项目的原因.

如果您要指定为什么需要选择此项,那么它也会有所帮助.

java – 如何以编程方式将webservice发布到tomcat

java – 如何以编程方式将webservice发布到tomcat

我想以编程方式向tomcat发布web服务.
例如JAX-WS或Apache CXF
与Endpoint.publish(…)类似.
//how to tell this tomcat?
Endpoint.publish("http://0.0.0.0:8080/SimpleService",serviceImpl);
//or better something like this:
Endpoint.publish("/SimpleService",serviceImpl);

无需使用web.xml和/或sun-jaxws.xml(对于每个服务)

题:
有没有任何已知的方法来实现它(使用JAX-WS或Apache CXF或……)?

(我知道已经发布了类似的问题.但是他们都没有回答我的问题.)

解决方法

这是我自己的问题.
我设法在Apache CXF的帮助下[以编程方式将webservice发布到tomcat].

这是一个简化的工作示例:

我将一个CXFNonspringServlet子类化并在web.xml中注册:

<servlet>
 <servlet-name>MyCXFServlet</servlet-name>
 <display-name>CXF Servlet</display-name>
 <servlet-class>de.test.MyCXFServlet</servlet-class>
 <load-on-startup>2</load-on-startup>
 <async-supported>true</async-supported>
</servlet>

<servlet-mapping>
 <servlet-name>MyCXFServlet</servlet-name>
 <url-pattern>/soap/*</url-pattern>
</servlet-mapping>

这是我的子类CXFNonspringServlet:

import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.HashSet;
import java.util.Set;
import javax.jws.WebMethod;
import javax.servlet.ServletConfig;
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.frontend.Serverfactorybean;
import org.apache.cxf.service.factory.ReflectionServicefactorybean;
import org.apache.cxf.transport.servlet.CXFNonspringServlet;

public class MyCXFServlet extends CXFNonspringServlet
{
    @Override
    protected void loadBus(ServletConfig sc) 
    {
        super.loadBus(sc);
        publishServices();
    }

    private void publishServices()
    {
        Set<Class> serviceInterfaces = new HashSet<>();
        serviceInterfaces.add(de.test.IUserService.class);
        serviceInterfaces.add(de.test.ILoginService.class);

        for (Class aSVCInterface : serviceInterfaces)
        {
            final String serviceName = aSVCInterface.getSimpleName();

            try
            {
                ReflectionServicefactorybean reflectionFactory = new ReflectionServicefactorybean(){
                    @Override
                    protected boolean isValidMethod(Method method)
                    {
                        boolean ret = super.isValidMethod(method);
                        WebMethod wm = method.getAnnotation(WebMethod.class);
                        if (wm != null && wm.exclude())
                            ret = false;
                        return ret;
                    }

                    @Override
                    protected String getServiceName() //Override for custom service name
                    {
                        return serviceName;
                    }

                };
                reflectionFactory.setServiceClass(aSVCInterface);

                Object proxiedServiceObject = Proxy.newProxyInstance(this.getClass().getClassLoader(),new Class[]{aSVCInterface},new de.test.MyWebServiceInvocationHandler(aSVCInterface));

                Serverfactorybean factory = new Serverfactorybean(reflectionFactory);
                factory.setBus(getBus());
                factory.setServiceClass(aSVCInterface);
                factory.setServiceBean(proxiedServiceObject);
                factory.setAddress("/" + serviceName);
                Server svr = factory.create();    
                svr.getEndpoint().getininterceptors().add(new de.test.MyServiceInterceptor());
            }
            catch (Exception exception)
            {
                exception.printstacktrace();
            }
        }
    }
}

上面的Servlet将发布2个简单的接口作为SOAP-WebService.
实现是动态的(代理)

这是我的MyServiceInterceptor:

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
import org.apache.cxf.binding.soap.soapMessage;
import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.message.Exchange;
import org.apache.cxf.phase.Phase;
import org.apache.cxf.service.Service;
import org.apache.cxf.service.invoker.BeanInvoker;
import org.apache.cxf.service.invoker.Invoker;

public class MyServiceInterceptor extends AbstractSoapInterceptor
{
    public MyServiceInterceptor() 
    {
        super(Phase.PRE_INVOKE);
    }

    @Override
    public void handleMessage(SoapMessage p_message) throws Fault 
    {
        final Exchange exchange = p_message.getExchange();
        final Endpoint endpoint = exchange.get(Endpoint.class);
        final Service service = endpoint.getService();
        final Invoker invoker = service.getInvoker();

        if (invoker instanceof BeanInvoker)
        {
            BeanInvoker bi = (BeanInvoker)invoker;
            Object serviceObj = bi.getServiceObject(null);
            if (Proxy.isProxyClass(serviceObj.getClass()))
            {
                InvocationHandler ih = Proxy.getInvocationHandler(serviceObj);
                if (ih instanceof MyWebServiceInvocationHandler)
                {
                    MyWebServiceInvocationHandler h = (MyWebServiceInvocationHandler)ih;
                    h.setSoapMessage(p_message);
                }
            }
        }
    }
}

MyServiceInterceptor-Class主要用于将当前SOAPMessage注入MyWebServiceInvocationHandler.

我的MyWebServiceInvocationHandler(我认为,这里不需要代码)负责调用真正的Service-Method.它只是实现了InvocationHandler并且有一个Soap-Message字段(参见MyServiceInterceptor).这是获取SOAPMessage-Details(如Header)所必需的.

希望这可以帮助.干杯!

java.lang.OutOfMemoryError:带有tomcat7 Windows服务的PermGen空间

java.lang.OutOfMemoryError:带有tomcat7 Windows服务的PermGen空间

我在 Windows Server 2008 R2 上运行 Tomcat 7.0.33 (我将Tomcat安装为Windows服务)


  • JDK版本: jdk1.6.0_25 64-bit
  • Tomcat选项:

    1. Java虚拟机:( C:\Program Files\Java\jre6\bin\server\jvm.dll 顺便说一句,我在jre中没有客户端文件夹)
    2. 初始内存池: 1000 MB
    3. 最大内存池: 2000 MB

当我检查服务器状态时,我可以看到服务器正在使用我配置的内存。

4. **环境变量(SYSTEM VARIABLES)配置:**  * **JAVA_HOME:** `C:\Program Files\Java\jdk1.6.0_25`  * **路径:** `...;%JAVA_HOME%\bin;....`

我是否还需要添加 CATALINA_HOMEJAVA_OPTS 系统变量?

问题: 我有两个Web应用程序 APP1 APP2 当我分别部署每个Web应用程序时,我可以找到用于以下用途的内存

APP1 = 198 MB APP2 = 104 MB

有关应用程序的信息:

APP1,APP2 :Spring Maven应用程序,在库中包括其他小型maven spring应用程序。

APP1:包含Web服务,APP2使用它们。

如果我试图将它们都部署在同一个tomcat实例上,我总是会得到

java.lang.OutOfMemoryError: PermGen space

请告知可能导致此问题的原因。

答案1

小编典典

解决方案是在设置初始和最大内存池的旁边,是-XX:MaxPermSize=1000m在java选项卡中添加到java选项。

我们今天的关于以编程方式将Tomcat的Java选项设置为Windows服务的方法tomcat编译java文件的分享已经告一段落,感谢您的关注,如果您想了解更多关于c# – 以编程方式启用Windows服务、c# – 如何以编程方式将RadComboBox与数据源设置为AutomaticLoadOnDemand、java – 如何以编程方式将webservice发布到tomcat、java.lang.OutOfMemoryError:带有tomcat7 Windows服务的PermGen空间的相关信息,请在本站查询。

本文标签: