NoClassDefFoundError使用Eclipse Cloud Foundry插件时

时间:2016-06-07 20:39:12

标签: eclipse maven cloudfoundry pivotal-cloud-foundry

所以我有一个maven项目,我最终构建成一个看起来像这样的jar:

C:\Users\myTest\TESTJAR-1.0-jar-with-dependencies.jar

如果我使用命令行推送到云代工厂,那么部署就可以了:

cf push newProject -p C:\Users\myTest\TESTJAR-1.0-jar-with-dependencies.jar

但是,当我尝试使用插件从Eclipse部署时,我得到以下内容

'java.lang.NoClassDefFoundError:org.slf4j.LoggerFactory'

任何帮助将不胜感激

enter image description here

的pom.xml

`  <project xmlns="http://maven.apache.org/POM/4.0.0"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0   http://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>

<groupId>test.myTest</groupId>
<artifactId>TESTJAR</artifactId>
<version>1.0</version>
<packaging>jar</packaging>   

<name>test</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>

<dependency> 
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2</version>
</dependency> 

<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>3.8.1</version>
  <scope>test</scope>
</dependency>



<!-- http://mvnrepository.com/artifact/ch.qos.logback/logback-classic  --> 
<dependency>
<groupId>ch.qos.logback</groupId> 
<artifactId>logback-classic</artifactId> 
<version>1.1.7</version>
</dependency>


<dependency>
<groupId>com.github.lalyos</groupId>
<artifactId>jfiglet</artifactId>
<version>0.0.7</version>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version> 
</dependency>


<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.6.1</version>
</dependency>

<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.8</version>
</dependency>


<dependency>  
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.3</version>

<exclusions>
  <exclusion> 
    <groupId>org.slf4j</groupId> 
    <artifactId>slf4j-log4j12</artifactId>
  </exclusion>
  <exclusion> 
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
  </exclusion>
</exclusions> 

</dependency>

<dependency> 
<groupId>com.microsoft.sqlserver</groupId> 
<artifactId>sqljdbc4</artifactId> 
<version>4.0</version> 
</dependency>

</dependencies>
 <build>
 <plugins>

 <plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-shade-plugin</artifactId>
  <version>2.4.3</version>
  <configuration>
  </configuration>
  <executions>
    <execution>
      <phase>package</phase>
      <goals>
        <goal>shade</goal>
      </goals>
    </execution>
  </executions>
</plugin>

<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
  <execution>
    <phase>package</phase>
    <goals>
      <goal>single</goal>
    </goals>
  </execution>
</executions>
<configuration>

  <archive>
  <manifest>
    <addClasspath>true</addClasspath>
    <mainClass>com.myTest.Main</mainClass>
  </manifest>
  </archive>

  <descriptorRefs>
    <descriptorRef>jar-with-dependencies</descriptorRef>
  </descriptorRefs>

  </configuration>
  </plugin>
  </plugins>
  </build>
  </project>'

1 个答案:

答案 0 :(得分:0)

可以使用Eclipse Cloud Foundry Tools(CFT)以两种方式将Jar打包的应用程序推送到Cloud Foundry:

  1. 使用“path”属性在Eclipse Maven项目中指定顶层的清单YAML文件,该文件指向要推送的文件系统中的jar。例如,在工作区项目MyTestMavenProject中,您需要有类似的东西:
  2. MyTestMavenProject / manifest.yml

    使用清单文件的内容

    ---   
    applications:
    - name: testjarapp
      path: C:\Users\myTest\TESTJAR-1.0-jar-with-dependencies.jar
    

    将包含此清单文件的项目拖放到Eclipse Servers视图中的Cloud Foundry目标。

    1. 在没有清单文件的情况下拖放Maven项目,CFT将在推送到Cloud Foundry之前自动打包应用程序。但是,这种机制对jar包装应用程序有一些已知问题。在某些情况下,需要在拖放之前手动刷新项目:

      • 刷新项目(通常为F5)
      • 右键点击项目:Maven - &gt;更新项目
      • 再次将Maven项目拖放到Servers视图中的CF目标上以查看它是否正确部署
    2. 这里有一个跟踪问题的错误:

      https://bugs.eclipse.org/bugs/show_bug.cgi?id=495814

      CFT里程碑大约每6周发布一次,因此Eclipse Neon(4.6)之后的下一个里程碑将针对jar包装应用程序的部署进行各种错误修复和改进。