部署java战争到heroku,pom.xml错误 [英] deploying java war to heroku ,pom.xml error

查看:205
本文介绍了部署java战争到heroku,pom.xml错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将java war部署到heroku。我在pom.xml中提到了下面的依赖关系。

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>

我已经运行

mvn package

,我跑了

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%


推荐答案

我也有类似的问题。

我钻了我的 pom 中的错误。
它与< build> 部分无关。

After head banging for 2 days, I drilled down to the error in my pom. It has nothing to do with the <build> section.

我的问题是pom.xml中的元数据有一个额外的< packaging> war< / packaging> 标签。

My problem was that the metadata in pom.xml had an extra <packaging>war</packaging> tag.

元数据到

        <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>

,一切顺利运行。

我希望这可以帮助你们。

I hope this helps you guys.

如果再次遇到此问题,请尝试重新构建您的 pom.xml 基于在heroku devcenter上提供的内容,然后添加依赖关系或任何增量。

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.

这篇关于部署java战争到heroku,pom.xml错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆