使用 JRebel 从 Eclipse 部署 Web 项目

发布于 2024-11-19 13:16:28 字数 1749 浏览 7 评论 0原文

我正在尝试使用 JRebel 将多模块 Maven 项目从 Eclipse 部署到本地 Tomcat。该项目具有以下结构:

root [packaging: pom]
|
|--- domain [packaging: jar
|
|--- manager [packaging: jar]
|
|--- web [packaging: war]

我在 3 个子模块中的每一个中创建了 src/main/resources/rebel.xml。我可以从 Eclipse 中将 Web 项目部署到 Tomcat(不使用 JRebel),没有任何问题。

但是,如果我 更改部署以使用 JRebel,我得到以下错误:

SEVERE: Exception sending context initialized event to listener instance 
of class com.web.listeners.WebAppListener
java.lang.IllegalArgumentException: Unknown entity: com.model.Role
....
....
Caused by: org.hibernate.MappingException: Unknown entity: com.model.Role

Role 是域项目中的持久性 (JPA/Hibernate) 类,它似乎是触发错误的 WebAppListener 中对其的引用

public class WebAppListener implements ServletContextListener, HttpSessionListener, 
        HttpSessionAttributeListener {

    private RoleManager roleManager;

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        BeanFactory beanFactory = WebApplicationContextUtils.
                    getRequiredWebApplicationContext(sce.getServletContext());
        this.roleManager = beanFactory.getBean(RoleManager.class);

        saveIfAbsent("USER", "Normal User");
    }

    private void saveIfAbsent(String roleName, String roleDescription) {

        if (roleManager.getRole(roleName) == null) {
            Role role = new Role();
            role.setName(roleName);
            role.setDescription(roleDescription);
            roleManager.saveRole(role);
        }
    }
}

:看起来像执行此代码时未加载 domain 类,知道如何解决此问题吗?

I'm trying to deploy a multi-module Maven project from Eclipse to a local Tomcat using JRebel. The project has the following structure:

root [packaging: pom]
|
|--- domain [packaging: jar
|
|--- manager [packaging: jar]
|
|--- web [packaging: war]

I've created src/main/resources/rebel.xml in each of the 3 child modules. I can deploy the web project to Tomcat (without using JRebel) from within Eclipse without any problems.

However, if I change the deployment to use JRebel, I get the following error:

SEVERE: Exception sending context initialized event to listener instance 
of class com.web.listeners.WebAppListener
java.lang.IllegalArgumentException: Unknown entity: com.model.Role
....
....
Caused by: org.hibernate.MappingException: Unknown entity: com.model.Role

Role is a persistent (JPA/Hibernate) class from the domain project and it appears to be the reference to it in WebAppListener that is triggering the error:

public class WebAppListener implements ServletContextListener, HttpSessionListener, 
        HttpSessionAttributeListener {

    private RoleManager roleManager;

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        BeanFactory beanFactory = WebApplicationContextUtils.
                    getRequiredWebApplicationContext(sce.getServletContext());
        this.roleManager = beanFactory.getBean(RoleManager.class);

        saveIfAbsent("USER", "Normal User");
    }

    private void saveIfAbsent(String roleName, String roleDescription) {

        if (roleManager.getRole(roleName) == null) {
            Role role = new Role();
            role.setName(roleName);
            role.setDescription(roleDescription);
            roleManager.saveRole(role);
        }
    }
}

It looks like the domain classes are not loaded when this code is executed, any idea how to fix this?

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

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

发布评论

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

评论(2

傲性难收 2024-11-26 13:16:28

你的反叛档案的内容是什么?它们应该看起来像

<classpath>
    <dir name="/absolute/path/to/projectname/target/classes"></dir>
</classpath>

如果您使用的是 Maven,您还可以查看相关主题:让 JRebel 与 'mvn tomcat:run' 一起使用

注意:如果rebel.xml还包含对 src/main/resources 的引用,有时它会
混淆了一些框架,如果发生错误,您应该尝试将其从所有rebel.xml 文件中删除。例如,以下conf很常见,但可能并不总是有效:

<classpath>
    <dir name="/absolute/path/to/projectname/target/classes"></dir>
    <dir name="/absolute/path/to/projectname/src/main/resources"></dir>
</classpath>

What is the contents of your rebel files? They should look like

<classpath>
    <dir name="/absolute/path/to/projectname/target/classes"></dir>
</classpath>

If you're using maven, you can also take a look at a related topic: Getting JRebel to work with 'mvn tomcat:run'

Note: if rebel.xml also contains a reference to src/main/resources, it sometimes
confuses some frameworks and you should try removing it from all rebel.xml files if errors occur. For example, the following conf is quite common, but may not always work:

<classpath>
    <dir name="/absolute/path/to/projectname/target/classes"></dir>
    <dir name="/absolute/path/to/projectname/src/main/resources"></dir>
</classpath>
允世 2024-11-26 13:16:28

删除来解决该问题

<dir name="/absolute/path/to/projectname/src/main/resources"></dir>

我通过从域项目中的rebel.xml 文件中 ,如此处所述

I fixed the problem by removing

<dir name="/absolute/path/to/projectname/src/main/resources"></dir>

from the rebel.xml file in the domain project as described here

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