我想将java war部署到heroku ..我在我的pom.xml中提到了下面的依赖项
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals><goal>copy-dependencies</goal></goals>
</execution>
</executions>
</plugin>
</plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<version>1.1.1</version>
<configuration>
<assembleDirectory>target</assembleDirectory>
<programs>
<program>
<mainClass>com.cim.Server.TomcatServer</mainClass>
<name>webapp</name>
</program>
</programs>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>assemble</goal>
</goals>
</execution>
</executions>
</plugin>
</build>
我跑了
mvn package
和我跑
D:\HUV\sri>java -cp target/classes:target/dependency/* com.cim.Server.TomcatServer
但即使我在上面的路径中有课程,我也会收到错误。我在哪里做错了?请帮忙
Exception in thread "main" java.lang.NoClassDefFoundError: com/cim/Server/Tomca
Server
Caused by: java.lang.ClassNotFoundException: com.cim.Server.TomcatServer
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: com.cim.Server.TomcatServer. Program will exit.
webapp.bat
@REM ----------------------------------------------------------------------------
@REM Copyright 2001-2004 The Apache Software Foundation.
@REM
@REM Licensed under the Apache License, Version 2.0 (the "License");
@REM you may not use this file except in compliance with the License.
@REM You may obtain a copy of the License at
@REM
@REM http://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing, software
@REM distributed under the License is distributed on an "AS IS" BASIS,
@REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@REM See the License for the specific language governing permissions and
@REM limitations under the License.
@REM ----------------------------------------------------------------------------
@REM
@echo off
set ERROR_CODE=0
:init
@REM Decide how to startup depending on the version of windows
@REM -- Win98ME
if NOT "%OS%"=="Windows_NT" goto Win9xArg
@REM set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" @setlocal
@REM -- 4NT shell
if "%eval[2+2]" == "4" goto 4NTArgs
@REM -- Regular WinNT shell
set CMD_LINE_ARGS=%*
goto WinNTGetScriptDir
@REM The 4NT Shell from jp software
:4NTArgs
set CMD_LINE_ARGS=%$
goto WinNTGetScriptDir
:Win9xArg
@REM Slurp the command line arguments. This loop allows for an unlimited number
@REM of arguments (up to the command line limit, anyway).
set CMD_LINE_ARGS=
:Win9xApp
if %1a==a goto Win9xGetScriptDir
set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
shift
goto Win9xApp
:Win9xGetScriptDir
set SAVEDIR=%CD%
%0\
cd %0\..\..
set BASEDIR=%CD%
cd %SAVEDIR%
set SAVE_DIR=
goto repoSetup
:WinNTGetScriptDir
set BASEDIR=%~dp0\..
:repoSetup
if "%JAVACMD%"=="" set JAVACMD=java
if "%REPO%"=="" set REPO=%BASEDIR%\repo
set CLASSPATH="%BASEDIR%"\etc;"%REPO%"\org\apache\tomcat\embed\tomcat-embed-core\7.0.27\tomcat-embed-core-7.0.27.jar;"%REPO%"\org\apache\tomcat\embed\tomcat-embed-logging-juli\7.0.27\tomcat-embed-logging-juli-7.0.27.jar;"%REPO%"\org\apache\tomcat\embed\tomcat-embed-jasper\7.0.27\tomcat-embed-jasper-7.0.27.jar;"%REPO%"\org\apache\tomcat\tomcat-jasper\7.0.27\tomcat-jasper-7.0.27.jar;"%REPO%"\org\apache\tomcat\tomcat-servlet-api\7.0.27\tomcat-servlet-api-7.0.27.jar;"%REPO%"\org\apache\tomcat\tomcat-juli\7.0.27\tomcat-juli-7.0.27.jar;"%REPO%"\org\apache\tomcat\tomcat-el-api\7.0.27\tomcat-el-api-7.0.27.jar;"%REPO%"\org\eclipse\jdt\core\compiler\ecj\3.7\ecj-3.7.jar;"%REPO%"\org\apache\tomcat\tomcat-api\7.0.27\tomcat-api-7.0.27.jar;"%REPO%"\org\apache\tomcat\tomcat-util\7.0.27\tomcat-util-7.0.27.jar;"%REPO%"\org\apache\tomcat\tomcat-jasper-el\7.0.27\tomcat-jasper-el-7.0.27.jar;"%REPO%"\org\apache\tomcat\tomcat-jsp-api\7.0.27\tomcat-jsp-api-7.0.27.jar;"%REPO%"\org\springframework\spring-context\3.0.6.RELEASE\spring-context-3.0.6.RELEASE.jar;"%REPO%"\org\springframework\spring-aop\3.0.6.RELEASE\spring-aop-3.0.6.RELEASE.jar;"%REPO%"\aopalliance\aopalliance\1.0\aopalliance-1.0.jar;"%REPO%"\org\springframework\spring-beans\3.0.6.RELEASE\spring-beans-3.0.6.RELEASE.jar;"%REPO%"\org\springframework\spring-core\3.0.6.RELEASE\spring-core-3.0.6.RELEASE.jar;"%REPO%"\org\springframework\spring-expression\3.0.6.RELEASE\spring-expression-3.0.6.RELEASE.jar;"%REPO%"\org\springframework\spring-asm\3.0.6.RELEASE\spring-asm-3.0.6.RELEASE.jar;"%REPO%"\org\springframework\spring-webmvc\3.0.6.RELEASE\spring-webmvc-3.0.6.RELEASE.jar;"%REPO%"\org\springframework\spring-context-support\3.0.6.RELEASE\spring-context-support-3.0.6.RELEASE.jar;"%REPO%"\org\springframework\spring-web\3.0.6.RELEASE\spring-web-3.0.6.RELEASE.jar;"%REPO%"\org\aspectj\aspectjrt\1.6.9\aspectjrt-1.6.9.jar;"%REPO%"\org\slf4j\slf4j-api\1.5.10\slf4j-api-1.5.10.jar;"%REPO%"\org\slf4j\jcl-over-slf4j\1.5.10\jcl-over-slf4j-1.5.10.jar;"%REPO%"\org\slf4j\slf4j-log4j12\1.5.10\slf4j-log4j12-1.5.10.jar;"%REPO%"\log4j\log4j\1.2.15\log4j-1.2.15.jar;"%REPO%"\javax\inject\javax.inject\1\javax.inject-1.jar;"%REPO%"\javax\servlet\jstl\1.2\jstl-1.2.jar;"%REPO%"\com\cim\controllers\1.0.0-BUILD-SNAPSHOT\controllers-1.0.0-BUILD-SNAPSHOT.war
set EXTRA_JVM_ARGUMENTS=
goto endInit
@REM Reaching here means variables are defined and arguments have been captured
:endInit
%JAVACMD% %JAVA_OPTS% %EXTRA_JVM_ARGUMENTS% -classpath %CLASSPATH_PREFIX%;%CLASSPATH% -Dapp.name="webapp" -Dapp.repo="%REPO%" -Dbasedir="%BASEDIR%" com.cim.Server.TomcatServer %CMD_LINE_ARGS%
if ERRORLEVEL 1 goto error
goto end
:error
if "%OS%"=="Windows_NT" @endlocal
set ERROR_CODE=1
:end
@REM set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" goto endNT
@REM For old DOS remove the set variables from ENV - we assume they were not set
@REM before we started - at least we don't leave any baggage around
set CMD_LINE_ARGS=
goto postExec
:endNT
@endlocal
:postExec
if "%FORCE_EXIT_ON_ERROR%" == "on" (
if %ERROR_CODE% NEQ 0 exit %ERROR_CODE%
)
exit /B %ERROR_CODE%
答案 0 :(得分:1)
我也有类似的问题。
头部撞击2天后,我深入查看pom
中的错误。
它与<build>
部分无关。
我的问题是pom.xml中的元数据有一个额外的<packaging>war</packaging>
标记。
我将元数据修改为
<modelVersion>4.0.0</modelVersion>
<groupId>com.my.apps</groupId>
<artifactId>DummyHerokuApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Dummy name</name>
<description>Dummy war</description>
<url>http://maven.apache.org</url>
一切顺利。
我希望这可以帮助你们。
如果再次遇到此问题,请尝试根据heroku devcenter上提供的内容重建pom.xml
,然后逐步添加依赖项或其他内容。
答案 1 :(得分:0)
根据您的pom.xml
文件,您使用appasssembler-maven-plugin
生成运行Java应用程序的脚本。尝试使用它。 Example
类似的东西:
Compile:
mvn package appassembler:assemble
Run:
target/appassembler/bin/app.bat
答案 2 :(得分:0)
我建议使用jcabi-heroku-maven-plugin,它会自动为您完成所有这些工作。您需要做的就是配置要运行的工件以及如何在那里运行它:
<plugin>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-heroku-maven-plugin</artifactId>
<version>0.4.1</version>
<configuration>
<name>my-test-app</name>
<artifacts>
<artifact>com.example:example-app:jar::${project.version}</artifact>
</artifacts>
<procfile>web: java -Xmx256m -jar ./example-app.jar \${PORT}</procfile>
</configuration>
<executions>
<execution>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
您需要在pom.xml
中配置。