【问题标题】:What is Heroku Procfile for Maven web application on Glassfish?Glassfish 上的 Maven Web 应用程序的 Heroku Procfile 是什么?
【发布时间】:2013-05-18 04:35:33
【问题描述】:

我在 Netbeans 上编写了一个简单的 Maven Web 应用程序。我的项目在 Glassfish 服务器上的本地主机上运行良好。我试图将我的项目上传到 Heroku,但我无法实现。什么是适合我的 Procfile?

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.mycompany</groupId>
<artifactId>tutorialspoint_jsf_2</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>

<name>tutorialspoint_jsf_2</name>

<properties>
    <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.1.7</version>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.1.7</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
                <compilerArguments>
                    <endorseddirs>${endorsed.dir}</endorseddirs>
                </compilerArguments>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1.1</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.1</version>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${endorsed.dir}</outputDirectory>
                        <silent>true</silent>
                        <artifactItems>
                            <artifactItem>
                                <groupId>javax</groupId>
                                <artifactId>javaee-endorsed-api</artifactId>
                                <version>6.0</version>
                                <type>jar</type>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

我试过了,但它不起作用:

web:    java -cp target/dependency/*:target/classes com.mycompany.tutorialspoint_jsf_2.jsfYonetimliNesne

对不起我的英语

【问题讨论】:

    标签: java maven netbeans heroku glassfish


    【解决方案1】:

    如果您希望您的应用程序在 Glassfish(在 Heroku 上)上运行,您必须使用嵌入式 Glassfish。你知道吗?

    <dependency>
       <groupId>org.glassfish.extras</groupId>
       <artifactId>glassfish-embedded-all</artifactId>
       <version>3.1.1</version>
    </dependency>
    

    作为 procfile 你可以使用例如:

    web:    java $JAVA_OPTS -cp target/classes:target/dependency/* com.example.Main
    

    在你的 main 中,你可以像这样开始你的 glassfish:

    String port = System.getenv("PORT");
    GlassFishProperties gfProps = new GlassFishProperties();
    gfProps.setPort("http-listener", Integer.parseInt(port));
    GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(gfProps);
    glassfish.start();          
    Deployer deployer = glassfish.getDeployer();            
    File file = new File("YourSimpleMavenWebapplication.war");      
    deployer.deploy(file);
    

    【讨论】:

    • 我将您的代码添加到我的项目中,但出现以下错误:Exception in thread "main" java.lang.NoClassDefFoundError: org/glassfish/embeddable/GlassFishException at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2451) at java.lang.Class.getMethod0(Class.java:2694) at java.lang.Class.getMethod(Class.java:1622) at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494) at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
    • Caused by: java.lang.ClassNotFoundException: org.glassfish.embeddable.GlassFishException at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:423) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    • 您有两个独立的项目?一个启动 glassfish 服务器并部署你的 war 文件。以及您的 webapp 的另一个项目(将被部署)
    • 不,我只有一个项目。我在 Netbeans 上创建了 Maven->Web 应用程序。
    • 也许您甚至不需要 glassfish,那么您可以使用 heroku eclipse 插件附带的演示项目之一。 (你可以在Tomcat和Jetty之间选择)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-16
    • 1970-01-01
    • 2016-11-03
    • 2017-08-04
    • 2019-03-13
    • 1970-01-01
    • 2013-12-23
    相关资源
    最近更新 更多