问题
i want to deploy java war to heroku..and i mentioned the dependencies like below in my 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>
and i have ran
mvn package
and the i ran
D:\HUV\sri>java -cp target/classes:target/dependency/* com.cim.Server.TomcatServer
but i got error even though i have the class in the path above..where am doing wrong??please help
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%
回答1:
I also had a similar problem.
After head banging for 2 days, I drilled down to the error in my pom
.
It has nothing to do with the <build>
section.
My problem was that the metadata in pom.xml had an extra <packaging>war</packaging>
tag.
I modified the metadata to
<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>
and everything is running smoothly.
I hope this helps you guys.
If you run into this problem again, try to rebuild your pom.xml
based on what has been provided on heroku devcenter and then add dependencies or whatever incrementally.
回答2:
According to your pom.xml
file you use appasssembler-maven-plugin
which generates script for running java appliction. Try to use it. Example
Something like:
Compile:
mvn package appassembler:assemble
Run:
target/appassembler/bin/app.bat
回答3:
I would recommend to use jcabi-heroku-maven-plugin, which does all this work for you automatically. All you need to do is to configure which artifact you want to run and how to run it there:
<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>
That's all you need to configure in pom.xml
.
来源:https://stackoverflow.com/questions/10330095/deploying-java-war-to-heroku-pom-xml-error