3

I am beginning the initial attempt to use Vert.x in Java. IDE is Netbeans version 8.1. Vert.x is version 3.0.0. The code for this project is shown below. The pom.xml file is also listed below. This code will run in Netbeans IDE but the Build (for jar file) will not complete without the error shown in the BUILD REPORT below. Thus, the generated jar file will not execute. I have researched every resource I could locate on the internet and cannot find an adequate solution/answer. I would appreciate any help anybody can offer to resolve this problem.

The POM file is generated by Netbeans IDE when creating a new project: File - New Project - Maven - Project from Archetype - vertx-java-archetype I then added the main() method.

DETAILED BUILD ERROR REPORT:

    --- maven-jar-plugin:2.3.2:jar (default-jar) @ mavenproject2 ---
    Building jar: C:\Projects\GenMatchJ\mavenproject2\target\mavenproject2-1.0-SNAPSHOT.jar

    --- maven-shade-plugin:2.3:shade (default) @ mavenproject2 ---
    Including io.vertx:vertx-core:jar:3.0.0 in the shaded jar.
    Including io.netty:netty-common:jar:4.0.28.Final in the shaded jar.
    Including io.netty:netty-buffer:jar:4.0.28.Final in the shaded jar.
    Including io.netty:netty-transport:jar:4.0.28.Final in the shaded jar.
    Including io.netty:netty-handler:jar:4.0.28.Final in the shaded jar.
    Including io.netty:netty-codec:jar:4.0.28.Final in the shaded jar.
    Including io.netty:netty-codec-http:jar:4.0.28.Final in the shaded jar.
    Including com.fasterxml.jackson.core:jackson-core:jar:2.5.3 in the shaded jar.
    Including com.fasterxml.jackson.core:jackson-databind:jar:2.5.3 in the shaded jar.
    Including com.fasterxml.jackson.core:jackson-annotations:jar:2.5.0 in the shaded jar.
    Including io.vertx:vertx-web:jar:3.0.0 in the shaded jar.
    Including io.vertx:vertx-auth-common:jar:3.0.0 in the shaded jar.

    --- exec-maven-plugin:1.3.2:exec (default) @ mavenproject2 ---
    ------------------------------------------------------------------------
    BUILD FAILURE
    ------------------------------------------------------------------------
    Total time: 3.290s
    Finished at: Sun Jun 05 13:01:40 EDT 2016
    Final Memory: 30M/313M
    ------------------------------------------------------------------------
    Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.3.2:exec (default) on project mavenproject2: The parameters 'executable' for goal org.codehaus.mojo:exec-maven-plugin:1.3.2:exec are missing or invalid -> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.

For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginParameterException

POM.XML FILE:

<?xml version="1.0" encoding="UTF-8"?>
<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>com.ssp</groupId>
  <artifactId>mavenproject2</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>io.vertx</groupId>
        <artifactId>vertx-dependencies</artifactId>
        <version>3.0.0</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>


  <dependencies>
    <dependency>
      <groupId>io.vertx</groupId>
      <artifactId>vertx-core</artifactId>
    </dependency>
    <dependency>
      <groupId>io.vertx</groupId>
      <artifactId>vertx-web</artifactId>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.3</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </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.Starter</Main-Class>
                    <Main-Verticle>com.ssp.mavenproject2.Main</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}/mavenproject2-${project.version}-fat.jar</outputFile>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.3.2</version>
        <executions>
          <execution>
            <phase>verify</phase>
            <goals>
              <goal>exec</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <mainClass>io.vertx.core.Starter</mainClass>
          <additionalClasspathElements>
            <additionalClasspathElement>${basedir}/src/main/java/</additionalClasspathElement>
          </additionalClasspathElements>
          <systemProperties>
            <systemProperty>
              <key>vertx.deployment.options.redeploy</key>
              <value>true</value>
            </systemProperty>
            <systemProperty>
              <key>vertx.deployment.options.redeployScanPeriod</key>
              <value>100</value>
            </systemProperty>
          </systemProperties>
          <arguments>
            <argument>run</argument>
            <argument>com/ssp/mavenproject2/Main.java</argument>
            <!--                  <argument>-cluster</argument>
            <argument>-cluster-host</argument>
            <argument>127.0.0.1</argument>-->
          </arguments>
        </configuration>
      </plugin>
    </plugins>
  </build>
    <name>MainSsp</name>
    <description>Main entry point for SSP Example with embedded Vert.x</description>
</project>

SOURCE CODE:

package com.ssp.mavenproject2;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Vertx;

import javax.swing.JOptionPane;


/**
 *
 */
public class Main extends AbstractVerticle {

  public static void main(String[] args) {


      JOptionPane.showMessageDialog(null, "This Vert.x/Java integration is UUUGGGGHH tough without documentation...");


      // Create an HTTP server which simply returns "Hello World!" to each request.
      Vertx.vertx().createHttpServer().requestHandler(req -> req.response().end("Hello World!")).listen(8080);

      Vertx.vertx().setPeriodic(3000, res -> {
        System.out.println("Periodic event triggered.");
      });

      try{

          Thread.sleep(30000);
      }catch(Exception e)
      {
         System.out.println("Exception caught");
      }
  }  

  @Override
  public void start() throws Exception {
    vertx.setPeriodic(3000, res -> {
      System.out.println("Periodic event triggered.");
    });
  }

}
Will
  • 6,561
  • 3
  • 30
  • 41
Rsh At The Fort
  • 31
  • 1
  • 1
  • 4

2 Answers2

0

It looks you're trying to run mvn exec:exec but for that you need to specify the executable (the error you're getting). In that case the executable should be your java binary, e.g.: /usr/java/latest/bin/java if you're using linux and the Oracle RPM.

Alternatively you should do: mvn exec:java which knows that the executable is java and knows how to pick the classpath dependencies from the pom file.

Now if you pay attention to your code you'll see that the public static void main method is never called, your exec plugin use the vert.x starter not your class, so when your app starts there won't be any server, just the periodic code executed inside the start method.

If you execute your main, then you're still missing to deploy your verticle so you have the server but no periodic task, in order to achieve that you need to add:

vertx.deployVerticle(Main.class.getName());
Paulo Lopes
  • 5,845
  • 22
  • 31
  • Replacing the 'exec<\goal>' with 'java<\goal>' results in successful and creation of a distributable jar file, which is fine. However, when I leave 'exec<\goal>' in the .pom file this error is created when the project is built (I am using the Netbeans IDE for code development and compilation). I have been unsuccessful in inserting the executable designation into this .pom file. I haven't been able to determine where the specification should be put and whether it needs a path alone or a path + filename. – Rsh At The Fort Jun 11 '16 at 12:09
  • One further comment. Thanks for the hint/advice on the syntax regarding the executable behavior of the code and the vertx deployment within main method. The behavior you mention matches the behavior when executing the code; running within the IDE causes the main() to get called and no periodic task. When executing from the command line, the vert.x starter is executed and there is no server, just the periodic timer. – Rsh At The Fort Jun 11 '16 at 12:14
0

Allow Netbeans to index the maven repository at

~\.m2\repository\org\codehaus\mojo

after the repository gets indexed everything should work fine.