C
C
ciasz2019-04-11 21:58:31
Java
ciasz, 2019-04-11 21:58:31

Running a java project locally on heroku?

I'm trying to locally launch a Java project on Heroku locally according to this guide: https://devcenter.heroku.com/articles/deploying-ja...
When executing the code, mvn clean installI get BUILD SUCCESS.
But when I write in the console heroku local webI get

Error: Could not find or load main class $JAVA_OPTS

Here is pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <version>1.0-SNAPSHOT</version>
    <artifactId>tgbot</artifactId>
    <dependencies>
        <dependency>
            <groupId>org.telegram</groupId>
            <artifactId>telegrambots</artifactId>
            <version>4.1.2</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.0.1</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals><goal>copy-dependencies</goal></goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Here is the procfile:
web: java $JAVA_OPTS -cp target/classes:target/dependency/* TgBot

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2019-04-11
@ciasz

The problem is that the environment variable doesn't expand into a set of arguments. This has two reasons. First, on Windows, environment variables are denoted differently. In addition, Windows uses different path and CLASSPATH separators. Therefore, you need to create an additional file - Procfile.windows with the following content:
Second, the JAVA_OPTS environment variable is not defined. This is solved by either removing it from the command or creating an .env file.
Finally, you need to tell heroku which file to run with:
heroku local -f Procfile.windows

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question