简体   繁体   English

Log4j,Tapestry 5.1,独立Jetty 6不能一起玩吗?

[英]Log4j, Tapestry 5.1, Stand-Alone Jetty 6 not playing along?

up to this point I have been developing a Tapestry 5.1.0.5 web-app using Maven goals to compile/package/execute the application. 到目前为止,我一直在开发一个Tapestry 5.1.0.5 Web应用程序,使用Maven目标来编译/打包/执行该应用程序。 I used the mvn jetty:run goal to run the Jetty maven plugin. 我使用了mvn jetty:run目标来运行Jetty maven插件。 This always worked fine. 这总是很好。 It seems Maven used Jetty 6.1.9. 看来Maven使用了Jetty 6.1.9。

I now need to setup a production environment that does NOT use maven goals for execution. 现在,我需要设置一个不使用Maven目标执行的生产环境。 I thought Jetty seemed simple enough and it was already working with Maven. 我认为Jetty看起来很简单,并且已经在与Maven合作。 I got 6.1.26 (later tried 6.1.9 too with no luck), got my application WAR file into the webapp directory and then tried to run it... no luck. 我得到了6.1.26(后来也没有运气尝试过6.1.9),将我的应用程序WAR文件放到了webapp目录中,然后尝试运行它……不走运。

Every single time I get this error, never changes: 每当我收到此错误,就永远不会改变:

2010-11-17 18:33:13.436:WARN::Error starting handlers
java.lang.NoClassDefFoundError: org/apache/log4j/Level
at org.slf4j.LoggerFactory.getSingleton(LoggerFactory.java:228)
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:120)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:111)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:269)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:242)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:255)
at org.apache.tapestry5.TapestryFilter.<init>(TapestryFilter.java:45)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at    sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at org.mortbay.jetty.servlet.Holder.newInstance(Holder.java:153)
at org.mortbay.jetty.servlet.FilterHolder.doStart(FilterHolder.java:92)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:713)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1282)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:518)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:499)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
at org.mortbay.jetty.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:156)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.jetty.Server.doStart(Server.java:224)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.xml.XmlConfiguration.main(XmlConfiguration.java:985)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.mortbay.start.Main.invokeMain(Main.java:194)
at org.mortbay.start.Main.start(Main.java:534)
at org.mortbay.start.Main.start(Main.java:441)
at org.mortbay.start.Main.main(Main.java:119)

I was initially using Log4J 1.2.8 as part of my manual dependencies for my application as a whole. 最初,我将Log4J 1.2.8用作整个应用程序手动依赖项的一部分。 I read this site http://tapestry.apache.org/tapestry5.1/jetty.html and then realized I ought to use 1.2.12 or higher for the TRACE level. 我阅读了该网站http://tapestry.apache.org/tapestry5.1/jetty.html ,然后意识到我应该为TRACE级别使用1.2.12或更高版本。 First I updated my dependency to LOG4J 1.2.16. 首先,我将依赖关系更新为LOG4J 1.2.16。 This did not work. 这没有用。

I then did some further reading that suggested the apache-commons-logging dependency can cause issues with logging at large due to how it works. 然后,我做了一些进一步的阅读,建议apache-commons-logging依赖项由于其工作方式而可能导致整个日志记录出现问题。 I went through my whole dependency hierarchy and excluded the apache-commons-logging from everything. 我遍历了整个依赖关系层次结构,并从所有内容中排除了apache-commons-logging。 The application still works with maven jetty plugin at this point, so I didn't break anything by doing this. 此时,该应用程序仍可与maven jetty插件一起使用,因此我并没有因此破坏任何东西。 But when I deploy the WAR, I still get the exception, so that was not the solution. 但是当我部署WAR时,仍然会遇到异常,因此这不是解决方案。

Next step I realized that the tapestry-ioc dependency was conflicting over log4j versions between my system side log4j and the one it wanted. 下一步,我意识到,tapestry-ioc依赖关系在系统端log4j和它想要的log4j版本之间发生冲突。 It seems that it uses log4j 1.2.13 and that the slf4j in the dependency itself uses a compile Log4J 1.2.14. 似乎它使用log4j 1.2.13,并且依赖项中的slf4j本身使用编译Log4J 1.2.14。

I updated my system dependency to be first 1.2.14 (since this error is occuring at slf4j in Tapestry) and then when that failed again with 1.2.13. 我将系统依赖关系更新为第一个1.2.14(因为该错误发生在Tapestry中的slf4j),然后又以1.2.13失败了。 Neither of these cases happened to work either. 这些案例都没有发生。

I've heard mention of making sure Jetty does not override your Log4J with a lower version it uses for its own logging. 我听说过要确保Jetty不会用用于自己的日志记录的较低版本覆盖Log4J。 Yet there is nowhere in the Jetty files that I can find any log4j dependency. 但是在Jetty文件中没有任何地方可以找到任何log4j依赖项。

i'm going to have a guess: 我将有一个猜测:

this 'could' be caused by 这“可能”是由

  1. when maven downloaded the log4j dependency, it failed or was corrupted - try deleting the log4j directory in your maven repository (windows: docs and settings/user/.m2/....) 当maven下载log4j依赖项时,它失败或损坏-尝试删除maven存储库中的log4j目录(Windows:docs and settings / user / .m2 / ....)

  2. there is some kind of dependency conflict and maven is doing a crap job at resolving it by not including either - this is unlikely, i think it would include the most up-to-date version 存在某种依赖关系冲突,并且Maven通过不包含任何一种解决方案来解决该问题-这不太可能,我认为它将包含最新版本

  3. some other maven plugin or configuration is causing the log4j jar to be excluded from the WAR creation (duh) 其他一些Maven插件或配置导致log4j jar从WAR创建(duh)中排除

dunno what else could cause this... 不知道还有什么可能导致这个...

EDIT re comment: 编辑重新评论:

ah yes, now that you mention it i have that problem to! 啊,是的,既然您提到它,我就有这个问题了! i have a couple of 'self managed' (ie not maven managed) jars and as far as i know the only way to include them in the maven classpath is to give them a system scope. 我有几个“自我管理”(即非Maven管理)的jars,据我所知,将它们包括在maven类路径中的唯一方法是给它们一个system范围。 your question becomes: "how do i include non-maven jars in the maven build?" 您的问题变为:“我如何在Maven构建中包括非Maven罐子?”

the documentation for the scope element: scope元素的文档:

The scope of the dependency - compile, runtime, test, system, and provided. 依赖项的范围-编译,运行时,测试,系统和提供。 Used to calculate the various classpaths used for compilation, testing, and so on. 用于计算用于编译,测试等的各种类路径。 It also assists in determining which artifacts to include in a distribution of this project. 它还有助于确定要在此项目的分发中包括哪些工件。 For more information, see the dependency mechanism. 有关更多信息,请参见依赖机制。

also an error you get in your pom if you change the scope of an entry with a systemPath: 如果您使用systemPath更改条目的范围,也会在pom中得到一个错误:

only dependency with system scope can specify systemPath. 只有具有系统范围的依赖项才能指定systemPath。

EDIT 2: found a good solution... 编辑2:找到了一个好的解决方案...

i found this 'issue' report , and followed the path suggested by the last comment: 我找到了这个“问题”报告 ,并遵循了最后一条评论所建议的路径:

We won't do this. 我们不会这样做。 I guess that you might add a webresource section with an include for the files you want and a targetPath. 我猜您可能会在webresource部分添加一个包含所需文件的文件和一个targetPath。

Here's the documentation regarding the mechanism. 这是有关该机制的文档。

so what you need to do is: 所以您需要做的是:

<build>
...
    <plugins>
...

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1.1</version>
            <configuration>
                <webResources>
                    <resource>
                        <directory>unmanaged-lib</directory>
                        <targetPath>WEB-INF/lib</targetPath>
                        <includes>
                            <include>**/*.jar</include>
                        </includes>
                    </resource>
                </webResources>
            </configuration>
        </plugin>

...
    <plugins>
...
<build>

note: the path 'unmanaged-lib' is a dir in the root of your project in this case (ie level with pom.xml) 注意:在这种情况下,路径“ unmanaged-lib”是项目根目录中的目录(即,带有pom.xml的目录)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM