首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Quartz.net as服务无法配置quartz_job.xml

Quartz.net as服务无法配置quartz_job.xml
EN

Stack Overflow用户
提问于 2015-06-08 22:46:35
回答 2查看 1.8K关注 0票数 2

在使用时

代码语言:javascript
复制
            var properties = new NameValueCollection();
            properties["quartz.plugin.triggHistory.type"] = "Quartz.Plugin.History.LoggingJobHistoryPlugin";

            properties["quartz.plugin.jobInitializer.type"] = "Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin";
            properties["quartz.plugin.jobInitializer.fileNames"] = "quartz_jobs.xml";
            properties["quartz.plugin.jobInitializer.failOnFileNotFound"] = "true";
            properties["quartz.plugin.jobInitializer.scanInterval"] = "120";

            // First we must get a reference to a scheduler
            _schedulerFactory = new StdSchedulerFactory(properties);
            _scheduler = _schedulerFactory.GetScheduler();

windows服务/ quartz无法解析quartz_jobs.xml的路径。如果我以控制台的身份运行它,它工作得很好。

代码语言:javascript
复制
  public static void StartJobs()
    {
        try
        {
            _logger = LogManager.GetCurrentClassLogger();

            var properties = new NameValueCollection();
            properties["quartz.plugin.triggHistory.type"] = "Quartz.Plugin.History.LoggingJobHistoryPlugin";

            properties["quartz.plugin.jobInitializer.type"] = "Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin";
            properties["quartz.plugin.jobInitializer.fileNames"] = "quartz_jobs.xml";
            properties["quartz.plugin.jobInitializer.failOnFileNotFound"] = "true";
            properties["quartz.plugin.jobInitializer.scanInterval"] = "120";

            // First we must get a reference to a scheduler
            _schedulerFactory = new StdSchedulerFactory(properties);
            _scheduler = _schedulerFactory.GetScheduler();

            // start the schedule 
            _scheduler.Start();
        }
        catch (Exception ex)
        {
            _logger.Error(ex);
            throw new Exception(ex.Message);
        }
    }
EN

回答 2

Stack Overflow用户

发布于 2015-06-09 00:50:03

如果它仍然不起作用,请将该文件作为嵌入式资源包含在项目中,并将操作设置为始终复制,以确保这一点。然后提供quartz属性的完整文件路径:

代码语言:javascript
复制
Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "quartz_jobs.xml")
票数 0
EN

Stack Overflow用户

发布于 2019-01-17 05:50:43

我知道这个帖子来自2015年,但我找不到任何关于在windows服务中使用quartz.net的信息。在我的例子中,我使用.Net Core2.1通用主机作为windows服务,并使用在我的appsettings.json文件中引用的quartz_jobs.xml。当windows服务启动并查找quartz_job.xml时,它会尝试在c:\windows\system32中找到它。但是我的quartz_job.xml位于我的可执行文件所在的位置。我在他们的存储库的Quaztz\Util\FileUtil.cs中找到了方法ResolveFile,其中表示将"~“放到相对文件中。所以我把我的appsettings.json改成

代码语言:javascript
复制
 "plugin": {
      "jobInitializer": {
        "type": "Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin, Quartz.Plugins",
        "fileNames": "~\\quartz_jobs.xml"
      }

现在,windows服务能够读取quartz_jobs.xml。我期待着如果你改变了

代码语言:javascript
复制
 properties["quartz.plugin.jobInitializer.fileNames"] = "quartz_jobs.xml";

代码语言:javascript
复制
properties["quartz.plugin.jobInitializer.fileNames"] = "~\\quartz_jobs.xml";

它也应该可以工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30712298

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档