java - 将 java war 部署到 heroku,pom.xml 错误

标签 java maven deployment heroku maven-plugin

我想将 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%

最佳答案

我也遇到了类似的问题。

苦苦思索了 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>

一切顺利。

希望对大家有帮助。

如果您再次遇到此问题,请尝试重建您的 pom.xml基于 heroku devcenter 上提供的内容,然后逐步添加依赖项或其他内容。

关于java - 将 java war 部署到 heroku,pom.xml 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10330095/

相关文章:

java - Grails - 将 Maven 依赖项添加到 Eclipse 类路径

c++ - 如果我想在运行时部署时查看图像,要加载什么 dll,还有我真正需要哪个 vc dll?

deployment - 通过 ClickOnce 部署后,客户端计算机上存储的 dll 在哪里?

java - 带有 HSQLDB : user lacks privilege or object not found 的 Spring 数据 JPA

java - 如何使用 SimpleDateFormat 格式化日期

java - 将数据存储在自定义检查异常中是一个坏主意吗?

c# - .net 核心应用程序错误 502.5 如果在 IIS 中作为虚拟目录运行

java - 无法使用 Californium Java 库设置 CoAP 服务器

java - 当特定类成员在发布版本之间更改值时破坏 Maven 构建的良好实践

maven - 如何在不使用cmd的情况下直接从intellij运行pom.xml