2015-07-11 188 views
1

我試圖部署Web應用程序,但它沒有工作,我與如何使用maven和tomcat部署Web應用程序?

  • IntelliJ IDEA的工作14.1.4
  • 運行OS X Yosemite 10.10.4

我有這個配置:

在Apache的行家-3.2.5(settings.xml中)

<server> 
    <id>TomcatServer</id> 
    <username>tomcatg</username> 
    <password>sg</password> 
</server> 

在Apache的Tomcat的7.0.63(Tomcat的users.xml中)

<tomcat-users> 

<role rolename="manager-gui"/> 
<role rolename="manager-script"/> 
<user username="tomcatg" password="sg" roles="manager-gui"/> 
<user username="tomcats" password="ss" roles="manager-script" /> 
</tomcat-users> 

在pom.xml中

<?xml version="1.0" encoding="UTF-8"?> 

http://maven.apache.org/xsd/maven-4.0。 0.xsd「> 4.0.0

<groupId>simple</groupId> 
<artifactId>simple</artifactId> 
<version>1.0-SNAPSHOT</version> 
<packaging>war</packaging> 
<dependencies> 
    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>javax.servlet-api</artifactId> 
     <version>3.1.0</version> 
     <scope>provided</scope> 
    </dependency> 

    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>slf4j-api</artifactId> 
     <version>1.5.6</version> 
     <type>jar</type> 
    </dependency> 

    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>slf4j-simple</artifactId> 
     <version>1.5.6</version> 
     <type>jar</type> 
    </dependency> 


</dependencies> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>3.1</version> 
      <configuration> 
       <source>1.7</source> 
       <target>1.7</target> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.tomcat.maven</groupId> 
      <artifactId>tomcat7-maven-plugin</artifactId> 
      <version>2.2</version> 
      <configuration> 
       <url>http://127.0.0.1:8080/manager/text/</url> 
       <server>TomcatServer</server> 
       <username>tomcatg</username> 
       <password>sg</password> 
       <path>/firstwebapp</path> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

我選擇tomcat7:部署和運行按Maven構建按鈕:

/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin/java "-Dmaven.home=/Applications/IntelliJ IDEA 14.app/Contents/plugins/maven/lib/maven3" "-Dclassworlds.conf=/Applications/IntelliJ IDEA 14.app/Contents/plugins/maven/lib/maven3/bin/m2.conf" -Didea.launcher.port=7533 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA 14.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/Applications/IntelliJ IDEA 14.app/Contents/plugins/maven/lib/maven3/boot/plexus-classworlds-2.4.jar:/Applications/IntelliJ IDEA 14.app/Contents/lib/idea_rt.jar" com.intellij.rt.execution.application.AppMain org.codehaus.classworlds.Launcher -Didea.version=14.1.4 org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:deploy 
[INFO] Scanning for projects... 
[INFO]                   
[INFO] ------------------------------------------------------------------------ 
[INFO] Building simple 1.0-SNAPSHOT 
[INFO] ------------------------------------------------------------------------ 
[INFO] 
[INFO] >>> tomcat7-maven-plugin:2.2:deploy (default-cli) @ simple >>> 
[INFO] 
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ simple --- 
[debug] execute contextualize 
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! 
[INFO] Copying 0 resource 
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ simple --- 
[INFO] Nothing to compile - all classes are up to date 
[INFO] 
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ simple --- 
[debug] execute contextualize 
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! 
[INFO] skip non existing resourceDirectory /Users/carloseduardoanguloustarez/IdeaProjects/simple/src/test/resources 
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ simple --- 
[INFO] Nothing to compile - all classes are up to date 
[INFO] 
[INFO] --- maven-surefire-plugin:2.10:test (default-test) @ simple --- 
[INFO] Surefire report directory: /Users/carloseduardoanguloustarez/IdeaProjects/simple/target/surefire-reports 

------------------------------------------------------- 
T E S T S 
------------------------------------------------------- 

Results : 

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0 

[INFO] 
[INFO] --- maven-war-plugin:2.1.1:war (default-war) @ simple --- 
[INFO] Packaging webapp 
[INFO] Assembling webapp [simple] in [/Users/carloseduardoanguloustarez/IdeaProjects/simple/target/simple-1.0-SNAPSHOT] 
[INFO] Processing war project 
[INFO] Copying webapp resources [/Users/carloseduardoanguloustarez/IdeaProjects/simple/src/main/webapp] 
[INFO] Webapp assembled in [26 msecs] 
[INFO] Building war: /Users/carloseduardoanguloustarez/IdeaProjects/simple/target/simple-1.0-SNAPSHOT.war 
[INFO] WEB-INF/web.xml already added, skipping 
[INFO] 
[INFO] <<< tomcat7-maven-plugin:2.2:deploy (default-cli) @ simple <<< 
[INFO] 
[INFO] --- tomcat7-maven-plugin:2.2:deploy (default-cli) @ simple --- 
[INFO] Deploying war to http://127.0.0.1:8080/firstwebapp 
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". 
SLF4J: Defaulting to no-operation (NOP) logger implementation 
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. 
Uploading: http://127.0.0.1:8080/manager/text//deploy?path=%2Ffirstwebapp 
2076/9092 KB 
Uploading: http://127.0.0.1:8080/manager/text//deploy?path=%2Ffirstwebapp 
2072/9092 KB 
Uploading: http://127.0.0.1:8080/manager/text//deploy?path=%2Ffirstwebapp 
2084/9092 KB 
Uploading: http://127.0.0.1:8080/manager/text//deploy?path=%2Ffirstwebapp 
2076/9092 KB 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 2.012s 
[INFO] Finished at: Sat Jul 11 11:38:07 BOT 2015 
[INFO] Final Memory: 12M/248M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:deploy (default-cli) on project simple: Cannot invoke Tomcat manager: Broken pipe -> [Help 1] 
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. 
[ERROR] Re-run Maven using the -X switch to enable full debug logging. 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles: 
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException 

Process finished with exit code 1 

,但我的web應用程序不會出現在Tomcat服務器管理員

我在做什麼錯?

+1

改換包裝。默認情況下,打包是jar。 – Seeker

回答

5

您正在構建jar文件。 /Users/carloseduardoanguloustarez/IdeaProjects/simple/target/simple-1.0-SNAPSHOT。 jar

Jar文件不能部署在Tomcat中。您可以按照流行方式在 中運行jar文件。

java -jar myhelloworldapp.jar 

如果它是一個Web應用程序,請改變包裝戰爭。通過 默認包裝是罐子。項目戰爭 maven

<modelVersion>4.0.0</modelVersion> 
    <groupId>simple</groupId> 
    <artifactId>simple</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>war</packaging> 
+0

是的你是對的,非常感謝。我有這個錯誤消息SLF4J:無法加載類「org.slf4j.impl.StaticLoggerBinder」。 SLF4J:默認爲無操作(NOP)記錄器實現..你知道如何解決這個問題嗎? – EduardoUstarez

+0

將'slf4j-api-1.5.6.jar'和'slf4j-simple-1.5.6.jar'添加到pom.xml中的maven依賴項中** ** org.slf4j.impl.StaticLoggerBinder.class存在於slf4j-simple -1.5.6.jar ** – Seeker

+0

我編寫了jlf4j的依賴關係(在pom.xml中可以看到上述問題中的代碼),但我無法解決問題。 – EduardoUstarez

0

看吧:maven-tomcat deploying

正如你可以看到有,有兩個可能的原因:

(1)你是不是認證

Tomcat管理URL品牌的

(2)路徑段麻煩

在案例1中,您應該使用 管理器腳本定義一個分離部署用戶。之後,你必須重新啓動tomcat。

在案例2中,您應該嘗試使用路徑:使用 經理/,經理,經理/文本,經理/文本/或他們的組合。 在某些較舊版本中,尾隨斜線的Tomcat帽子問題。

相關問題