1

I'm trying to get started with Betfair's streaming API for Java, but am having trouble building/running their sample application. Here are the steps that I've taken so far...

Clone project:

git clone https://github.com/betfair/stream-api-sample-code.git

In Eclipse, "Import Projects from File System or Archive", and open the stream-api-sample-code/java folder

I now see client, console and swagger projects in my Package explorer.

At the bottom of the Eclipse window, I see 2 Errors:

The project cannot be built until its prerequisite client is built. Cleaning and building all projects is recommended
The project cannot be built until its prerequisite swagger is built. Cleaning and building all projects is recommended

I assume this is because I need to create the swagger files as described here:

https://docs.developer.betfair.com/display/1smk3cen4v3lu3yomq5qye0ni/Exchange+Stream+API#ExchangeStreamAPI-SwaggerDefinition

So I run this command inside the /stream-api-sample-code folder:

java -jar swagger-codegen-cli-2.2.1.jar generate -i ESASwaggerSchema.json -l java -o java/swagger

I now have lots of files inside /stream-api-sample-code/java/swagger. Before running the command I just had a pom.xml file in there.

I wasn't sure what to do next, but in eclipse I right-clicked on the swagger project, and selected "Update Project". I now see all the new files in eclipse.

But I now get 888 Errors, such as "AuthenticationMessage cannot be resolved to a type".

What should I try next?

Ginger
  • 8,320
  • 12
  • 56
  • 99
  • 1
    The problem I could find so far is, since it is a multi-module maven project, importing it to eclipse is the problem, else `mvn clean install -DskipTests` works fine. Eclipse is not able to locate `swagger-1.0-SNAPSHOT.jar` dependency for client and hence error for client, now console is dependent on client so console is not able to find client (only in eclipse) – dkb Jan 18 '19 at 11:33
  • 1
    Import it in intelliJ-idea, it is working fine, here is snapshot: https://i.stack.imgur.com/typ8X.png – dkb Jan 18 '19 at 11:47
  • 1
    you do not need to run command `java -jar swagger-codegen-cli-2.2.1.jar` – dkb Jan 18 '19 at 11:48
  • 1
    You can refer stream-api-specification.pdf file present in github. – dkb Jan 18 '19 at 11:59
  • @dkb THanks for the suggestion. I imported the /streaming-api-sample-code/java/ folder into IntelliJ And then tried to build the project, but it then gives me the errors here: https://imgur.com/gallery/vVDJhjS – Ginger Jan 18 '19 at 22:38
  • After that, I tried running the command `java -jar swagger-codegen-cli-2.2.1.jar`, and it then told me that the Android SDK was not specified. I don't know why it wants an Android SDK for this. I'll try installing it later. – Ginger Jan 18 '19 at 22:39
  • 1
    I tried with Java-8 though, you need to select JDK for your project (go to View --> Open Module Settings --> Project Settings --> Project --> Project SDK) and rebuild. – dkb Jan 19 '19 at 14:44
  • 1
    one of the solution to "no idea annotations attached to the jdk 11 intellij":https://stackoverflow.com/a/52912715/2987755 – dkb Jan 19 '19 at 14:46

1 Answers1

2

First, add this:

   <dependencies>
    ...
    <dependency>
        <groupId>javax.annotation</groupId>
        <artifactId>javax.annotation-api</artifactId>
        <version>1.3.2</version>
    </dependency>
   ...
   </dependencies>

..to swagger/pom.xml.

This makes the project build-able. (It should be reported&easy fixed.)

------------------------------------------------------------------------
Reactor Summary:

esa-java-client .................................... SUCCESS [  0.625 s]
swagger ............................................ SUCCESS [ 13.746 s]
client ............................................. SUCCESS [  9.434 s]
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 24.259 s
Finished at: 2019-01-23T22:48:56+01:00
Final Memory: 26M/90M
------------------------------------------------------------------------

Second: java -jar swagger-codegen-cli-2.2.1.jar generate -i ESASwaggerSchema.json -l java ..generates you a (completley new/different) maven project, so please do not:

-o java/swagger

but:

-o java/someothernewfolder

...this generated project you can also import into eclipse ...and it has the same "bug" (see First)). So please also add javax.annotation dependency & build (someothernewfolder).

xerx593
  • 12,237
  • 5
  • 33
  • 64
  • thanks for the tip. How did you generate that Reactor Summary: ? – Ginger Jan 24 '19 at 10:34
  • Thanks. I got it to work. Though I also had to give it my AppKey and login details before it would run the tests. Did you have to give it those details as well? – Ginger Jan 24 '19 at 16:16
  • I didn't need to update the dependencies to make it work, but I'll mark your answer as the correct answer as the maven thing fixed it. – Ginger Jan 24 '19 at 16:17
  • BTW, on my machine I had to type mvn build..., not maven build. Do you know why? I can't find much info on the difference between maven and mvn on Google. – Ginger Jan 24 '19 at 16:18
  • ...nice, that it worked! yea, i stuck on the build/test of "console", due to missing appkey, credentials. regarding dependency: confused! ..regarding accept: thank you! :) – xerx593 Jan 24 '19 at 16:20
  • "maven" is humanly speaking "mvn" is the name of the command line tool/executable :) – xerx593 Jan 24 '19 at 16:21
  • Thanks for the clarification. How did you "stuck on the build/test of "console""? Apologies for the basic questions but I'm not really a Java developer. – Ginger Jan 24 '19 at 16:29
  • a test failed (during `mvn clean install`), with the according message: "no appkey found....stacktrace" – xerx593 Jan 24 '19 at 16:31
  • Coming late to this, but one way is to ensure that you pass the credentials on the command line, or as options passed to your vm: `-DAppKey= -DUserName= -DPassword=` – Etuka Onono Mar 13 '23 at 13:49