我正在尝试将java-SpringBoot项目(构建一个messenger bot)部署到
中heroku,但是当我尝试使用时: heroku本地 命令,我收到此错误:
Error: A JNI error has occurred, please check your
installation and try again
Exception in thread "main"
java.lang.NoClassDefFoundError:
com/github/messenger4j/send/MessengerSendClient
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at
sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at
sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException:
com.github.messenger4j.send.MessengerSendClient
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)... 7 more
我的Procfile看起来像这样:
web: java $JAVA_OPTS -cp target/classes:target/dependency/* me.messengerBot.SpringDocBotApplication
我的主要课程:
@SpringBootApplication
public class SpringDocBotApplication {
private static final Logger logger = LoggerFactory.getLogger(SpringDocBotApplication.class);
/**
* Initializes the {@code MessengerSendClient}.
*
* @param pageAccessToken the generated {@code Page Access Token}
*/
@Bean
public MessengerSendClient
messengerSendClient(@Value("${messenger4j.pageAccessToken}")
String pageAccessToken) {
logger.debug("Initializing MessengerSendClient - pageAccessToken: {}", pageAccessToken);
return MessengerPlatform.newSendClientBuilder(pageAccessToken).build();
}
public static void main(String[] args) {
SpringApplication.run(SpringDocBotApplication.class, args);
}
}
我的配置是application.yml,它包含身份验证值。
我的pom文件:
仅限依赖项和插件:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.github.messenger4j</groupId>
<artifactId>messenger4j</artifactId>
<version>0.8.0</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.10.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
java java.lang.ClassNotFoundException / NoClassDefFoundError有很多不同的答案,我已经尝试过了。
我认为这是一个java类路径问题(因为它是从命令行运行的)但是所有在线建议对我都不起作用。