5

I am trying to configure the Procfile file for Heroku platform to run the application locally. I am trying to run a Tomcat-based Java Web Application.

In the tutorial they say:

To build your app locally do this:
Use the Git Bash application to open a command shell on Windows.
$ mvn clean install
$ heroku local web

I am in the project directory and after mvn clean install I receive

BUILD SUCCESS

The problem is when I run: heroku local web I receive [WARN] No ENV file found web.1 | Error: Could not find or load main class $JAVA_OPTS

My Procfile has 1 line:

web: java $JAVA_OPTS -jar target/dependency/webapp-runner.jar --port $PORT target/*.war

I am using Windows. I saw a post on stack and they were saying that the code on Windows in the Procfile is different. It should look something like this(my creation):

web: java %JAVA_OPTS% -jar target\dependency\webapp-runner.jar --port %PORT% target*.war

I have to create a folder called "dependency" in the target folder? because I don't have webbapp-runner.jar in my project and I don't understand what should I do.

Here is my 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.rares</groupId>
<artifactId>first-web-application</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<dependencies>
    <dependency>
        <groupId>com.github.jsimone</groupId>
        <artifactId>webapp-runner</artifactId>
        <version>8.5.11.2</version>
    </dependency>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>4.3.6.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>
</dependencies>

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                    <verbose>true</verbose>
                    <source>1.8</source>
                    <target>1.8</target>
                    <showWarnings>true</showWarnings>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <path>/</path>
                    <contextReloadable>true</contextReloadable>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

Should I add the webapp-runner as a plugin?

Community
  • 1
  • 1
ProgIsMetal
  • 462
  • 2
  • 5
  • 18
  • did you try other solutions from the same post you've shared? Like `web: java %JAVA_OPTS% -cp target\classes;"target\dependency\*" Main`. You can follow [this](https://devcenter.heroku.com/articles/deploying-java#the-procfile) – Naman Mar 08 '17 at 03:39
  • what it is my Main class? I have just a LoginController java class and Login Service ..a class for my controller with a method – ProgIsMetal Mar 08 '17 at 06:00
  • @ProhIsMetal Service class should be the one. Ideally the class that you want to startup your application from. – Naman Mar 08 '17 at 06:01
  • I will post later the logs with the errors when I try to upload it to heroku. But I can t basicaly make a local server for the app because of this error...I want to test it local because when I run the application with tomcat in eclipse I can see at localhost:8080/login what I want. I want to mention that my LoginService class has just 1 method isTrue which return true or false. Are you sure if that can fix the problem? – ProgIsMetal Mar 08 '17 at 06:46
  • 1
    If you could vote the question it would be great! Maybe someone knows a better solution. Thanks! – ProgIsMetal Mar 08 '17 at 06:51

2 Answers2

2

You need to add webapp-runner to your pom.xml like this:

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>2.3</version>
        <executions>
            <execution>
                <phase>package</phase>
                <goals><goal>copy</goal></goals>
                <configuration>
                    <artifactItems>
                        <artifactItem>
                            <groupId>com.github.jsimone</groupId>
                            <artifactId>webapp-runner</artifactId>
                            <version>8.5.11.2</version>
                            <destFileName>webapp-runner.jar</destFileName>
                        </artifactItem>
                    </artifactItems>
                </configuration>
            </execution>
        </executions>
    </plugin>

Then your Procfile can look like this:

web: java $JAVA_OPTS -jar target/dependency/webapp-runner.jar --port $PORT target/*.war

And your Procfile.windows can look (something) like this:

web: java %JAVA_OPTS% -jar target\dependency\webapp-runner.jar --port %PORT% target\*.war

For more information see Deploying Tomcat-based Java Web Applications with Webapp Runner.

codefinger
  • 10,088
  • 7
  • 39
  • 51
  • Please use [uptodate versions of plugins](https://maven.apache.org/plugins/maven-dependency-plugin/) and not so ancient versions... – khmarbaise Mar 08 '17 at 15:40
  • I have to define somewhere $JAVA_OPTS? – ProgIsMetal Mar 08 '17 at 16:55
  • When I run : mvn package I receive build succes and after java -jar target/dependency/webapp-runner.jar target/*.war I receive: error unable to access jarfile target/dependency/webapp-runner.jar – ProgIsMetal Mar 08 '17 at 17:05
1

So I read alot of posts on stackoverflow about this error + tutorials on Heroku and didn't find a solution but I made a improvement. I read this post and deleted the start <pluginManagement> and end <pluginManagement/> tags in pom.xml and now the dependency directory and the webapp-runner-8.0.30.1.jar are created. My application is working because if I run my app in Eclipse with Tomcat I can go to localhost:8080/login and I can see my website. When I run :

mvn package

I receive build succes and after that I run in cmd

java -jar target/dependency/webapp-runner.jar target/*.war

I receive: error invalid or corrupt jarfile target/dependency/webapp-runner.jar

Here is my Procfile:

web: java $JAVA_OPTS -jar target/dependency/webapp-runner.jar --port $PORT target/*.war

Here is my Procfile.windows:

web: java %JAVA_OPTS% -jar target\dependency\webapp-runner.jar --port %PORT% target*.war

My 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.rares</groupId>
<artifactId>first-web-application</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<dependencies>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>4.3.6.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>
</dependencies>

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                    <verbose>true</verbose>
                    <source>1.8</source>
                    <target>1.8</target>
                    <showWarnings>true</showWarnings>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <path>/</path>
                    <contextReloadable>true</contextReloadable>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.3</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>com.github.jsimone</groupId>
                                    <artifactId>webapp-runner</artifactId>
                                    <version>8.5.11.2</version>
                                    <destFileName>webapp-runner.jar</destFileName>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
</build>

Community
  • 1
  • 1
ProgIsMetal
  • 462
  • 2
  • 5
  • 18