2016-06-21 75 views
0

我想用Java部署JavaScipt编写的Verticle。但我总是得到一个ClassNotFoundErrorException - 虽然路径是正确的,并且添加了vertx-lang-js资源。Vert.x:从Java部署JavaScript Verticle失败

这是我的JS-Verticle:

declare var vertx;  
var eb = new vertx.EventBus() 
eb.consumer("cbweb.validation", (message:any) => { 
    console.log(message); 
}); 
console.log("Validation.js ready") 

这里是我的Java代码部署Verticle:

private static final String RELATIVE_PATH = "D:/Temp/vertxFtpClient/jslibs/jsftp/verticle.js"; 

public static void main(String[] args) throws InterruptedException { 
    Vertx vertx = Vertx.vertx(); 
    vertx.deployVerticle(new BasicVerticle(), stringAsyncResult -> { 
     System.out.println("BasicVerticle deployment complete"); 
    }); 


    vertx.deployVerticle(RELATIVE_PATH); 

    vertx.close(); 

} 

}

,这里是我如何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>de.vertex.ftp</groupId> 
    <artifactId>VertexAdapter</artifactId> 
    <version>1.0</version> 
    <packaging>war</packaging> 
    <dependencies> 
     <dependency> 
      <groupId>io.vertx</groupId> 
      <artifactId>vertx-core</artifactId> 
      <version>3.2.1</version> 
     </dependency> 
     <dependency> 
      <groupId>io.vertx</groupId> 
      <artifactId>vertx-lang-js</artifactId> 
      <version>3.1.0</version> 
     </dependency> 
    </dependencies> 
    <build> 
     <finalName>VertexLearning</finalName> 
    </build> 
    <properties> 
     <maven.compiler.source>1.8</maven.compiler.source> 
     <maven.compiler.target>1.8</maven.compiler.target> 
     <failOnMissingWebXml>false</failOnMissingWebXml> 
    </properties> 
</project> 

也许失踪了?

回答

1

如果您只想使用JavaScript,则根本不需要编写Java代码。所有你需要的是添加你的js代码到src/main/resources(你可以改变这个东西,但你需要调整maven不要使用它的默认值)。

和使用maven shade plugin就象这样:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-shade-plugin</artifactId> 
    <version>2.3</version> 
    <executions> 
    <execution> 
     <phase>package</phase> 
     <goals> 
     <goal>shade</goal> 
     </goals> 
     <configuration> 
     <transformers> 
      <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> 
      <manifestEntries> 
       <Main-Class>io.vertx.core.Launcher</Main-Class> 
       <Main-Verticle>${main.verticle}</Main-Verticle> 
      </manifestEntries> 
      </transformer> 
      <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> 
      <resource>META-INF/services/io.vertx.core.spi.VerticleFactory</resource> 
      </transformer> 
     </transformers> 
     <artifactSet> 
     </artifactSet> 
     <outputFile>${project.build.directory}/${project.artifactId}-${project.version}-fat.jar</outputFile> 
     </configuration> 
    </execution> 
    </executions> 
</plugin> 

,并声明文件路径相对verticle可变main.verticle与JS从src/main/resource例如为:jslibs/jsftp/verticle.js