我对Maven不是很熟悉,昨天才开始用,但我喜欢它。在我的项目中,我使用 Log4j2 库进行日志记录,并且由于高级插件(如附加程序、转换器)的不足,我需要使用自定义插件。 log4j-api 和 log4j-core(还有许多其他库)作为依赖项添加到与我的项目关联的 pom.xml 中。实际上,我使用的是 Log4j 的 2.0 版。
Log4j 使用注释处理来预加载标记为@Plugin 的类。据我所知,在旧版本的 log4j 中,必须在 pom.xml 中指定额外的插件条目才能触发插件处理,或者必须将带有自定义插件的包键入 配置文件中的 packages 属性 ( https://logging.apache.org/log4j/2.x/manual/configuration.html#ConfigurationSyntax )。但是从 2.0-rc2 开始就不再支持了。
在 v2.0 中,只要 log4j-core 可用于构建引擎,这应该会自动完成。 myproject-0.0.1-SNAPSHOT.jar/META-INF/org/apache/logging/log4j/core/config/plugins/ 中有一个文件Log4j2Plugins.dat包含我的自定义插件的映射 - 没关系。
为了使用 Maven 进行构建,我还使用了 Maven Assembly Plugin .它的目标 single 绑定(bind)到 package 阶段。打包项目后,我自然会在 target 目录中多一个 jar - myproject-0.0.1-SNAPSHOT-jar-with-dependencies.jar。但是,此 jar 中的 Log4j2Plugins.dat 文件包含原始插件的映射,与 log4j-core 库中的文件相同。这就是问题所在,因为它没有对我的自定义插件的任何引用。 myproject-0.0.1-SNAPSHOT.jar 中的文件似乎被 log4j 库中的原始文件覆盖,但我不确定是怎么回事。
因此,当我运行 myproject-0.0.1-SNAPSHOT-jar-with-dependencies.jar 时,log4j 无法从我的项目中找到插件类。我认为 myproject-0.0.1-SNAPSHOT.jar 可以正常运行,但没有依赖项我无法运行它。
configuration中的packages属性应该在2.0.1版本重新启用,但如果不想等到release,就得用注解处理的方式。
你知道如何解决它吗?
我尝试使用 log4j 的 2.0-rc1 版本运行它,其中配置元素的 packages 属性可用。结果是:log4j 成功加载了我自定义插件的类。但是,还有许多其他错误(在这个特定版本中出现)使程序更加无法使用。
这是一个好点,它向我保证,如果 packages 属性将在下一个版本 2.0.1 中启用,我的插件将 工作。它应该根据这个问题跟踪恢复:https://issues.apache.org/jira/browse/LOG4J2-741
添加了我的pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jjurm</groupId>
<artifactId>twbot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>twbot</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.jjurm.twbot.system.Run</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.jjurm.twbot.system.Run</mainClass>
</manifest>
</archive>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>1.1.7</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<version>1.10</version>
</dependency>
<dependency>
<groupId>net.snaq</groupId>
<artifactId>dbpool</artifactId>
<version>6.0</version>
</dependency>
<dependency>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi</artifactId>
<version>1.11</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>commons-jxpath</groupId>
<artifactId>commons-jxpath</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.15</version>
</dependency>
</dependencies>
</project>
最佳答案
我认为问题源于将依赖项打包到 jar 中。快速深入研究代码,看起来插件处理器会为它处理的每组插件覆盖插件 dat 文件。我的猜测是,在打包过程中,您的自定义插件被处理并写入 dat 文件,然后在处理您的 log4j 依赖项以包含在包中时被覆盖。可能有更好的解决方案,但我建议您执行以下操作之一:
不要将依赖项打包到您的 jar 中。只需打包您的项目,然后在执行时将依赖项包含在您的类路径中。即使您想将所有内容打包到一个可移植 jar 中,这样做至少可以让您确认您的插件是否被覆盖,或者是否存在其他问题。
为您的自定义插件创建一个单独的项目,将其与主项目分开打包,然后将生成的 jar 作为依赖项包含在内。与选项 1 一样,请确保您不在此包中包含 log4j jar。创建自定义插件 jar 后,您可以将它与主 jar 中的其他依赖项一起打包,它应该可以正常工作,因为您的自定义插件 jar 将有自己的插件 dat 文件。
祝你好运!
关于java - Log4j2 自定义插件 - 使用 Maven Assembly Plugin 进行注释处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25065580/
我想向我的Controller传递一个参数,它是一个简单的复选框,但我不知道如何在模型的form_for中引入它,这是我的观点:{:id=>'go_finance'}do|f|%>Transferirde:para:Entrada:"input",:placeholder=>"Quantofoiganho?"%>Saída:"output",:placeholder=>"Quantofoigasto?"%>Nota:我想做一个额外的复选框,但我该怎么做,模型中没有一个对象,而是一个要检查的对象,以便在Controller中创建一个ifelse,如果没有检查,请帮助我,非常感谢,谢谢
我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www
我正在使用RubyonRails3.0.9,我想生成一个传递一些自定义参数的link_toURL。也就是说,有一个articles_path(www.my_web_site_name.com/articles)我想生成如下内容:link_to'Samplelinktitle',...#HereIshouldimplementthecode#=>'http://www.my_web_site_name.com/articles?param1=value1¶m2=value2&...我如何编写link_to语句“alàRubyonRailsWay”以实现该目的?如果我想通过传递一些
我只想对我一直在思考的这个问题有其他意见,例如我有classuser_controller和classuserclassUserattr_accessor:name,:usernameendclassUserController//dosomethingaboutanythingaboutusersend问题是我的User类中是否应该有逻辑user=User.newuser.do_something(user1)oritshouldbeuser_controller=UserController.newuser_controller.do_something(user1,user2)我
有这些railscast。http://railscasts.com/episodes/218-making-generators-in-rails-3有了这个,你就会知道如何创建样式表和脚手架生成器。http://railscasts.com/episodes/216-generators-in-rails-3通过这个,您可以了解如何添加一些文件来修改脚手架View。我想把两者结合起来。我想创建一个生成器,它也可以创建脚手架View。有点像RyanBates漂亮的生成器或web_app_themegem(https://github.com/pilu/web-app-theme)。我
什么是ruby的rack或python的Java的wsgi?还有一个路由库。 最佳答案 来自Python标准PEP333:Bycontrast,althoughJavahasjustasmanywebapplicationframeworksavailable,Java's"servlet"APImakesitpossibleforapplicationswrittenwithanyJavawebapplicationframeworktoruninanywebserverthatsupportstheservletAPI.ht
是否有简单的方法来更改默认ISO格式(yyyy-mm-dd)的ActiveAdmin日期过滤器显示格式? 最佳答案 您可以像这样为日期选择器提供额外的选项,而不是覆盖js:=f.input:my_date,as::datepicker,datepicker_options:{dateFormat:"mm/dd/yy"} 关于ruby-on-rails-事件管理员日期过滤器日期格式自定义,我们在StackOverflow上找到一个类似的问题: https://s
这篇文章是继上一篇文章“Observability:从零开始创建Java微服务并监控它(一)”的续篇。在上一篇文章中,我们讲述了如何创建一个Javaweb应用,并使用Filebeat来收集应用所生成的日志。在今天的文章中,我来详述如何收集应用的指标,使用APM来监控应用并监督web服务的在线情况。源码可以在地址 https://github.com/liu-xiao-guo/java_observability 进行下载。摄入指标指标被视为可以随时更改的时间点值。当前请求的数量可以改变任何毫秒。你可能有1000个请求的峰值,然后一切都回到一个请求。这也意味着这些指标可能不准确,你还想提取最小/
HashMap中为什么引入红黑树,而不是AVL树呢1.概述开始学习这个知识点之前我们需要知道,在JDK1.8以及之前,针对HashMap有什么不同。JDK1.7的时候,HashMap的底层实现是数组+链表JDK1.8的时候,HashMap的底层实现是数组+链表+红黑树我们要思考一个问题,为什么要从链表转为红黑树呢。首先先让我们了解下链表有什么不好???2.链表上述的截图其实就是链表的结构,我们来看下链表的增删改查的时间复杂度增:因为链表不是线性结构,所以每次添加的时候,只需要移动一个节点,所以可以理解为复杂度是N(1)删:算法时间复杂度跟增保持一致查:既然是非线性结构,所以查询某一个节点的时候