阿托米克斯+ Maven 构建环境中的 Jetty - 类加载器问题?

发布于 2024-08-03 20:32:12 字数 6363 浏览 13 评论 0原文

我正在开发一个具有多个 JDBC 数据源和 JTA 的项目。我使用 Maven 作为构建工具,并且我想在开发过程中使用 Jetty 插件 (6.1.20) 来运行应用程序。

我正在尝试将 Jetty 配置为使用 Atomikos 作为事务管理器。我正在关注 Jetty 的 Atomikos 文档,但是 Jetty 启动失败,看起来如下就像类加载器问题。

这是我的配置的相关部分。

pom.xml 中的 runtime 范围依赖项:

<dependency>
    <groupId>com.atomikos</groupId>
    <artifactId>transactions-jta</artifactId>
    <version>3.5.7</version>
    <scope>runtime</scope>
</dependency>
<dependency>
    <groupId>com.atomikos</groupId>
    <artifactId>transactions-jdbc</artifactId>
    <version>3.5.7</version>
    <scope>runtime</scope>
</dependency>
<dependency>
    <groupId>javax.transaction</groupId>
    <artifactId>jta</artifactId>
    <version>1.1</version>
    <scope>runtime</scope>
</dependency>

我的 jetty-env.xml 位于 /WEB-INF (由 Jetty 自动发现):

<New id="userTxImpl" class="com.atomikos.icatch.jta.UserTransactionImp" />

<New id="tx" class="org.mortbay.jetty.plus.naming.Transaction">
    <Arg>
        <Ref id="userTxImpl" />
    </Arg>
</New>

最后的 tx 实例化是失败的部分,如果我忽略它,Jetty 会正常启动(但不会通过 JNDI 公开 UserTransaction , 当然)。

Stacktrace:

    2009-09-02 18:42:18.910::WARN:  Config error at <New id="tx" class="org.mortbay.jetty.plus.naming.Transaction"><Arg>
            <Ref id="userTxImpl"/>
        </Arg></New>
2009-09-02 18:42:18.910::WARN:  Failed startup of context org.mortbay.jetty.plugin.Jetty6PluginWebAppContext@12515db{/administrator,C:\workspace\administrator\src\main\webapp}
java.lang.IllegalStateException: No Constructor: <New id="tx" class="org.mortbay.jetty.plus.naming.Transaction"><Arg>
            <Ref id="userTxImpl"/>
        </Arg></New> on org.mortbay.jetty.plugin.Jetty6PluginWebAppContext@12515db{/administrator,C:\workspace\administrator\src\main\webapp}
    at org.mortbay.xml.XmlConfiguration.newObj(XmlConfiguration.java:631)
    at org.mortbay.xml.XmlConfiguration.configure(XmlConfiguration.java:256)
    at org.mortbay.xml.XmlConfiguration.configure(XmlConfiguration.java:190)
    at org.mortbay.jetty.plus.webapp.EnvConfiguration.configureWebApp(EnvConfiguration.java:130)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1247)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
    at org.mortbay.jetty.plugin.Jetty6PluginWebAppContext.doStart(Jetty6PluginWebAppContext.java:124)
    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.jetty.plugin.Jetty6PluginServer.start(Jetty6PluginServer.java:132)
    at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:441)
    at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:383)
    at org.mortbay.jetty.plugin.AbstractJettyRunMojo.execute(AbstractJettyRunMojo.java:210)
    at org.mortbay.jetty.plugin.Jetty6RunMojo.execute(Jetty6RunMojo.java:184)
    at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:579)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:498)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmentForProject(DefaultLifecycleExecutor.java:265)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:191)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:149)
    at org.apache.maven.DefaultMaven.execute_aroundBody0(DefaultMaven.java:223)
    at org.apache.maven.DefaultMaven.execute_aroundBody1$advice(DefaultMaven.java:304)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:1)
    at org.apache.maven.embedder.MavenEmbedder.execute_aroundBody2(MavenEmbedder.java:904)
    at org.apache.maven.embedder.MavenEmbedder.execute_aroundBody3$advice(MavenEmbedder.java:304)
    at org.apache.maven.embedder.MavenEmbedder.execute(MavenEmbedder.java:1)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:176)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:63)
    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.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:408)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:351)
    at org.codehaus.classworlds.Launcher.main(Launcher.java:31)

这看起来像是一个类加载器问题,因为 org.mortbay.jetty.plus.naming.Transaction 有一个构造函数采用 javax.transaction.UserTransaction,并且 < code>com.atomikos.icatch.jta.UserTransactionImp 实现了 javax.transaction.UserTransaction,但 Jetty 抱怨它没有合适的构造函数可供使用。

我显然在这里遗漏了一些东西,但它是什么?

谢谢!

I am working on a project with multiple JDBC data sources and JTA. I use Maven as a build tool, and I'd like to use the Jetty plugin (6.1.20) to run the application during development.

I am trying to configure Jetty to use Atomikos as the transaction manager. I'm following the Atomikos documentation from Jetty, but the Jetty startup fails with what looks like a class loader issue.

Here are the relevant bits of my configuration.

runtime scope dependencies in my pom.xml:

<dependency>
    <groupId>com.atomikos</groupId>
    <artifactId>transactions-jta</artifactId>
    <version>3.5.7</version>
    <scope>runtime</scope>
</dependency>
<dependency>
    <groupId>com.atomikos</groupId>
    <artifactId>transactions-jdbc</artifactId>
    <version>3.5.7</version>
    <scope>runtime</scope>
</dependency>
<dependency>
    <groupId>javax.transaction</groupId>
    <artifactId>jta</artifactId>
    <version>1.1</version>
    <scope>runtime</scope>
</dependency>

My jetty-env.xml located in /WEB-INF (autodiscovered by Jetty):

<New id="userTxImpl" class="com.atomikos.icatch.jta.UserTransactionImp" />

<New id="tx" class="org.mortbay.jetty.plus.naming.Transaction">
    <Arg>
        <Ref id="userTxImpl" />
    </Arg>
</New>

The instantiation of tx at the end is the bit that fails, if I leave it out, Jetty starts up fine (but does not expose UserTransaction via JNDI, of course).

The Stacktrace:

    2009-09-02 18:42:18.910::WARN:  Config error at <New id="tx" class="org.mortbay.jetty.plus.naming.Transaction"><Arg>
            <Ref id="userTxImpl"/>
        </Arg></New>
2009-09-02 18:42:18.910::WARN:  Failed startup of context org.mortbay.jetty.plugin.Jetty6PluginWebAppContext@12515db{/administrator,C:\workspace\administrator\src\main\webapp}
java.lang.IllegalStateException: No Constructor: <New id="tx" class="org.mortbay.jetty.plus.naming.Transaction"><Arg>
            <Ref id="userTxImpl"/>
        </Arg></New> on org.mortbay.jetty.plugin.Jetty6PluginWebAppContext@12515db{/administrator,C:\workspace\administrator\src\main\webapp}
    at org.mortbay.xml.XmlConfiguration.newObj(XmlConfiguration.java:631)
    at org.mortbay.xml.XmlConfiguration.configure(XmlConfiguration.java:256)
    at org.mortbay.xml.XmlConfiguration.configure(XmlConfiguration.java:190)
    at org.mortbay.jetty.plus.webapp.EnvConfiguration.configureWebApp(EnvConfiguration.java:130)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1247)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
    at org.mortbay.jetty.plugin.Jetty6PluginWebAppContext.doStart(Jetty6PluginWebAppContext.java:124)
    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.jetty.plugin.Jetty6PluginServer.start(Jetty6PluginServer.java:132)
    at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:441)
    at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:383)
    at org.mortbay.jetty.plugin.AbstractJettyRunMojo.execute(AbstractJettyRunMojo.java:210)
    at org.mortbay.jetty.plugin.Jetty6RunMojo.execute(Jetty6RunMojo.java:184)
    at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:579)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:498)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmentForProject(DefaultLifecycleExecutor.java:265)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:191)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:149)
    at org.apache.maven.DefaultMaven.execute_aroundBody0(DefaultMaven.java:223)
    at org.apache.maven.DefaultMaven.execute_aroundBody1$advice(DefaultMaven.java:304)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:1)
    at org.apache.maven.embedder.MavenEmbedder.execute_aroundBody2(MavenEmbedder.java:904)
    at org.apache.maven.embedder.MavenEmbedder.execute_aroundBody3$advice(MavenEmbedder.java:304)
    at org.apache.maven.embedder.MavenEmbedder.execute(MavenEmbedder.java:1)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:176)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:63)
    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.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:408)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:351)
    at org.codehaus.classworlds.Launcher.main(Launcher.java:31)

This looks like a classloader issue, as org.mortbay.jetty.plus.naming.Transaction has got a Constructor taking a javax.transaction.UserTransaction, and com.atomikos.icatch.jta.UserTransactionImp implements javax.transaction.UserTransaction, yet Jetty complains it does not have a proper constructor to use.

I'm obviously missing something here, but what is it?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

情栀口红 2024-08-10 20:32:12

您的部署中可能有多个 UserTransaction 类的副本。如果这些是从不同的类加载器加载的,那么最终可能会出现此类错误。

检查 Jetty 的 UserTransaction 库,然后检查您的应用程序的库。您应该只有一份副本。

You may have multiple copies of the UserTransaction class kicking around in your deployment. If these are loaded from different classloaders, then you can end up with this sort of error.

Check Jetty's libraries for UserTransaction, and then check your application's libraries. You should only have one copy.

葬心 2024-08-10 20:32:12

我认为您不应该将 JTA jar 指定为“运行时”要求,而应将其指定为“提供”要求。与 servlet-api 和 JMS 类似,各个实现者提供自己的 API 副本,而提供 Sun jar 可能会搞砸它们。

I believe that you should not be specifying the JTA jar as a 'runtime' requirement, but rather as a 'provided' requirement. Similar to servlet-api and JMS, the individual implementers provide their own copies of the API and providing the Sun jar can muck them up.

心房的律动 2024-08-10 20:32:12

我意识到这个问题已经得到了解答,但我想把我的经验分享出来,以拯救其他人我刚刚经历的悲伤。

我遇到了类似的问题,但它是由 geronimo-jta 规范版本冲突引起的。具体来说,atomikos 所依赖的那个与 jetty 使用的那个并不一致。我必须从atomikos中排除这一点,例如:

com.atomikos
交易必需品全部
3.5.9

org.apache.geronimo.specs
geronimo-jta_1.0.1B_spec

I realize this is already answered, but I wanna put up my experience to save others the grief I just went through.

I had a similar problem, but it was caused by a conflict in versions of geronimo-jta spec. Specifically the one depended on by atomikos wasn't getting along with the one used by jetty. I had to exclude the one from atomikos, e.g.:

com.atomikos
transactions-essentials-all
3.5.9

org.apache.geronimo.specs
geronimo-jta_1.0.1B_spec

小情绪 2024-08-10 20:32:12

和泰勒一样,我在这个完全相同的问题上花了几个小时。我使用 Hibernate 作为 JPA 提供程序,它在自己的 JTA 用户事务上有 Maven 依赖关系。一旦我排除了这种依赖性,我就解决了这个问题。

Like Taylor, I just blew a couple hours on this exact same issue. I use Hibernate as a JPA provider and it had a Maven depdency on its own JTA User Tranaction. Once I excluded this dependency I got past the issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文