带码头的 PermGen 空间

Ski*_*zzo 5 java jetty maven-3 maven

我正在开发一个 java web 应用程序,我在其中使用 mavenlike 项目管理工具。现在我的问题是,如果我以这种方式每 20 秒设置一次自动扫描的码头:

<!-- To launch embded jetty server -->
       <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>${maven-jetty-plugin.version}</version>
            <configuration>
                <scanIntervalSeconds>10</scanIntervalSeconds>
                <webAppConfig>
                    <contextPath>/${project.name}</contextPath>
                    <extraClasspath>target/classes;../services/target/classes;</extraClasspath>
                </webAppConfig>
                <scanTargets>
                    <scanTarget>target/classes</scanTarget>
                    <scanTarget>../services/target/classes</scanTarget>
                </scanTargets>
            </configuration>
        </plugin>
Run Code Online (Sandbox Code Playgroud)

Jetty 以正确的方式开始,事实上我得到:

[信息] 启动 Jetty 服务器

[信息] 以 20 秒的间隔启动扫描仪。

但是在第一次扫描时,我收到以下错误:

错误 ContextLoader - 上下文初始化失败

java.lang.OutOfMemoryError: PermGen 空间

我该怎么做才能解决它?

更新 1

我尝试以这种方式从我的 Eclipse Ide 增加 PermGen 空间:

在此处输入图片说明

但在第一次扫描后,我得到了同样的错误。

我该怎么做才能解决它?

Jir*_*ser 6

把它放在<configuration>元素下:<jvmArgs>-XX:PermSize=256M -XX:MaxPermSize=512M</jvmArgs>

因此 Maven 插件将如下所示:

<!-- To launch embded jetty server -->
       <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>${maven-jetty-plugin.version}</version>
            <configuration>
                <jvmArgs>-XX:PermSize=256M -XX:MaxPermSize=512M</jvmArgs>
                <scanIntervalSeconds>10</scanIntervalSeconds>
                <webAppConfig>
                    <contextPath>/${project.name}</contextPath>
                    <extraClasspath>target/classes;../services/target/classes;</extraClasspath>
                </webAppConfig>
                <scanTargets>
                    <scanTarget>target/classes</scanTarget>
                    <scanTarget>../services/target/classes</scanTarget>
                </scanTargets>
            </configuration>
        </plugin>
Run Code Online (Sandbox Code Playgroud)

注意:如果它失败并显示无法分配这么多内存的消息,请使用较低的数字。


Bil*_*sky 5

你试过在JDK8下运行吗?PermGen 已被 MetaSpace 取代,可能会解决您的 PermGen 问题:http : //www.infoq.com/news/2013/03/java-8-permgen-metaspace

Jetty 还有一些关于防止类加载器泄漏的文档,这些泄漏可能会填满 permgen:http : //www.eclipse.org/jetty/documentation/current/preventing-memory-leaks.html


小智 1

尝试使用传递给 MAVEN_OPTS 的 -XX:MaxPermSize=512m 来增加 MaxPermGen 空间。