Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core HA example doesn't run on command line #89

Closed
purplefox opened this issue Sep 30, 2015 · 17 comments
Closed

core HA example doesn't run on command line #89

purplefox opened this issue Sep 30, 2015 · 17 comments

Comments

@purplefox
Copy link
Contributor

If you follow the instructions to run it as described in the README it fails when starting the first Server:

/home/tim/projects/vert-x3/vertx-examples/core-examples/src/main/java/io/vertx/example/util/Runner.java:15: error: cannot find symbol
ExampleRunner.runJavaExample(CORE_EXAMPLES_JAVA_DIR, clazz, true);
^
symbol: variable ExampleRunner
location: class io.vertx.example.util.Runner
/home/tim/projects/vert-x3/vertx-examples/core-examples/src/main/java/io/vertx/example/util/Runner.java:19: error: cannot find symbol
ExampleRunner.runJavaExample(CORE_EXAMPLES_JAVA_DIR, clazz, false);
^
symbol: variable ExampleRunner
location: class io.vertx.example.util.Runner
/home/tim/projects/vert-x3/vertx-examples/core-examples/src/main/java/io/vertx/example/util/Runner.java:25: error: cannot find symbol
ExampleRunner.runScriptExample(CORE_EXAMPLES_JS_DIR, scriptName, false);

@cescoffier
Copy link
Member

Yes, here are the right command line:

vertx run Server.java -ha -cluster-host 192.168.1.29 -cp ../../../../../../../../target/classes/:/Users/clement/Projects/vert.x/vertx-examples/examples-utils/target/classes

and

vertx bare -cluster-host 192.168.1.29 -cp ../../../../../../../../target/classes/:/Users/clement/Projects/vert.x/vertx-examples/examples-utils/target/classes

not really convenient, will find a different way.

@cescoffier
Copy link
Member

(cluster-host is required on my computer because of my fancy network configuration)

@purplefox
Copy link
Contributor Author

I think for Java examples like this it doesn't really make sense to run them on the command line.

Running in the IDE would be much simpler, so probably just easier to update the README so it talks about running in the IDE only.

@cescoffier
Copy link
Member

Ok, but I need to start a bare instance from the IDE, and then kill a processus started by the IDE.

@purplefox
Copy link
Contributor Author

Just a thought. The main issue in running the Java examples from the command line is that they reference the ExampleRunner class...

Maybe instead of using that class we can use Launcher directly and change Launcher so it looks at vertx.cwd? Then we wouldn't have deps on other classes.

@purplefox
Copy link
Contributor Author

We could also put the logic for cwd that resolves the cwd as I mentioned in another issue so this works seamlessly on Eclipse, NetBeans and IntelliJ?

@cescoffier
Copy link
Member

It would give something like:

// Convenience method so you can run it in your IDE
  public static void main(String[] args) {
    String exampleDir = "web-examples/src/main/java/" +  Server.class.getPackage().getName().replace(".", "/");

    try {
      // We need to use the canonical file. Without the file name is .
      File current = new File(".").getCanonicalFile();
      if (exampleDir.startsWith(current.getName())  && ! exampleDir.equals(current.getName())) {
        exampleDir = exampleDir.substring(current.getName().length() + 1);
      }
    } catch (IOException e) {
      // Ignore it.
    }

    Launcher.main(new String[] {
        "run",
        Server.class.getName(),
        "-Dvertx.cwd=" + exampleDir
    });
  }

WDYT ?

@purplefox
Copy link
Contributor Author

Yes, like that, but I was thinking we should put the adjustment (i.e. the code inside the try..catch block) inside Launcher. Also you wouldn't need the "web-examples/src/main/java" part.

@cescoffier
Copy link
Member

We can do it in Launcher or in a "run-example" command. It would give something like:

Launcher.main(new String[] {
        "run-example",
        Server.class.getName()
    });

It can traverse the file system to find the associated Server.java file and set the vertx.cwd system property.

cescoffier added a commit that referenced this issue Sep 30, 2015
* Use Launcher
* Add IDE and command line instructions

Related to #89
@cescoffier
Copy link
Member

I've fixed the HA example, using the Launcher. I've provided the instructions for the IDE and command line.

@purplefox
Copy link
Contributor Author

Perfect

@purplefox
Copy link
Contributor Author

I notice the other examples are still using the ExampleRunner (as reported on a user report in the google group today)

@cescoffier
Copy link
Member

Yes, the ExampleRunner is still used. The "intelligent cwd detection" has been implemented here.

@purplefox
Copy link
Contributor Author

Ah ok. I thought we were going to implement in Launcher (as mentioned in your example above)?

Then the example only has dependencies on core code and is much easier to run without having to depend on ExampleRunner....

@cescoffier
Copy link
Member

Yes, but it was too close to the 3.1 deadline to implement this in the launcher. It will be in 3.2 (it's on my todo list).

@purplefox purplefox reopened this Oct 14, 2015
@cescoffier
Copy link
Member

It's not the same issue. This one was about running HA which has been fixed. Replacing the ExampleRunner should be another issue (I'm going to create one for this)

@cescoffier
Copy link
Member

Closing this one as the replacement of the ExampleRunner is covered by #97

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants