sarxos / ryzom-network-client

This is Java client for LV-20 Ryzom Network, crafted by the Matis engineers after studies performed on very ancient amber cubes found at the Megacorp SAT01-B satellite crash site near Sandy Workshop of Aeden Aqueous.
MIT License
1 stars 2 forks source link

Sample code problem: client.send(Chat.UNIVERSE, "Hello Atys!"); #1

Closed mambrus closed 8 years ago

mambrus commented 8 years ago

The line in the header produces a compilation error:

Lv20ClientTest.java:23: error: cannot find symbol
                        client.send(Chat.UNIVERSE, "Hello Atys!");

Remarked, the rest of the code works with the exception in issue #2

sarxos commented 8 years ago

Hi @mambrus,

How did you import the project into your IDE, or maybe question should be rather - how are you running it? I'm asking because this is Maven project and it should run without a need of any additional steps after you import it, or run from command line as long as you are using Maven for this - it's enough to import project using pom.xml file.

After you do git clone:

$ git clone git@github.com:sarxos/ryzom-network-client.git

In Eclipse (I'm not using other IDEs so I cannot give you details from NetBeans or IntelliJ), rightclick on the workspace and select "Import" and then select "Existing Maven project":

1

Browse into directory where you cloned the repo (where pom.xml file is located):

3

After clicking on "Finish" project will be imported into workspace. If you have Java 8 you should have no problems with the compilation errors.

You can also build it from command line (you need to have Maven installed):

$ git clone git@github.com:sarxos/ryzom-network-client.git
$ cd ryzom-network-client
$ mvn clean install

If it's the first time you hear about Maven, it may be a little hard to understand how it works, but there a dozens of tutorials on the web. It's just another build tool that helps you manage project dependencies and various build steps.

sarxos commented 8 years ago

Just FYI, I added import statements in README example, so this issue should not persist any more (as long as you imported it as Maven project, or added required dependencies manually).

mambrus commented 8 years ago

Hello!

Glad that you documented the requirements, at least here :-P

I'm running the project without any IDE using only JDK8 to build the code and vim as editor.

#Get CLASSPATH below as mentioned in issue #4
source $(pwd)/.env
javac Lv20ClientTest.java
java Lv20ClientTest

Testcode:

import com.github.sarxos.ryzom.network.*;

class Lv20ClientTest {
    public static void main(String[] args) throws InterruptedException {
        try (Lv20Client client = new Lv20Client()) {
            client.login("OneToon", "ApassWord");
            client.tell("AnotherToon", "Woha ##!.");
            //client.send(Chat.UNIVERSE, "Hello Atys!");
            Thread.sleep(1000);
        }   
    }   
}

Code above compiles and is confirmed to work (i.e. delivers message from one ~toon to another). With the exception of the remarked line, ryzom-network-client delivers.

I believe this issue actually isn't related to library dependencies, or at least shouldn't be as I already went trough all those who were.

mambrus commented 8 years ago

The error was in my code:

import com.github.sarxos.ryzom.network.*;

...isn't enough. Replacing with the following lines from your updated example works.

import com.github.sarxos.ryzom.network.Lv20Client;
import com.github.sarxos.ryzom.network.Lv20Client.Chat;

Passes compilation & runs as intended (confirmed).

Add an class around the main method and the example is perfect and you can dismiss this issue as solved.

sarxos commented 8 years ago

@mambrus, this is because asterisk * used as a wildcard load classes from the package only. It does not import static inner classes, in this case Lv20Client.Chat.

mambrus commented 8 years ago

These instructions are for old school people that for some reason prefer not to use IDE's or other tools to manage Java-projects.

Note: It's probably best to follow the instructions by the developer (see above in this thread).

If Maven is not used

The following jar-files are needed and are not included in Oracle's JDK8 bundle (latest stable version as of writing mentioned) and needed if Maven isn't used to build the project.

For convenience, copy & paste the following CLASSPATH info into a file, for example .env.

CLASSPATH+=":$(pwd)/lib/jetty-util-9.3.6.v20151106.jar"
CLASSPATH+=":$(pwd)/lib/jetty-io-9.3.6.v20151106.jar"
CLASSPATH+=":$(pwd)/lib/websocket-common-9.3.6.v20151106.jar"
CLASSPATH+=":$(pwd)/lib/websocket-client-9.3.6.v20151106.jar"
CLASSPATH+=":$(pwd)/lib/websocket-api-9.3.6.v20151106.jar"
CLASSPATH+=":$(pwd)/lib/jackson-core-2.6.4.jar"
CLASSPATH+=":$(pwd)/lib/jackson-databind-2.6.4.jar"
CLASSPATH+=":$(pwd)/lib/jackson-annotations-2.6.4.jar"
CLASSPATH+=":$(pwd)/lib/slf4j-api-1.7.13.jar"
CLASSPATH+=":$(pwd)/lib/slf4j-simple-1.7.13.jar"
export CLASSPATH

Before compilation and run, source the file:

# Use full path when sourcing to avoid sourcing any other .env-file in PATH by mistake
source $(pwd)/.env

Paths above are just examples to where you can put your missing libraries and should be changed to fit. To get the missing jar-files, Maven repository can for example be used.

Manual download of each required jar-file:

Open a terminal and copy&paste the following into it:

mkdir lib
cd lib
wget -O jetty-util-9.3.6.v20151106.jar http://central.maven.org/maven2/org/eclipse/jetty/jetty-util/9.3.6.v20151106/jetty-util-9.3.6.v20151106.jar
wget -O jetty-io-9.3.6.v20151106.jar http://central.maven.org/maven2/org/eclipse/jetty/jetty-io/9.3.6.v20151106/jetty-io-9.3.6.v20151106.jar
wget -O websocket-common-9.3.6.v20151106.jar http://central.maven.org/maven2/org/eclipse/jetty/websocket/websocket-common/9.3.6.v20151106/websocket-common-9.3.6.v20151106.jar
wget -O websocket-client-9.3.6.v20151106.jar http://central.maven.org/maven2/org/eclipse/jetty/websocket/websocket-client/9.3.6.v20151106/websocket-client-9.3.6.v20151106.jar
wget -O websocket-api-9.3.6.v20151106.jar http://central.maven.org/maven2/org/eclipse/jetty/websocket/websocket-api/9.3.6.v20151106/websocket-api-9.3.6.v20151106.jar
wget -O jackson-core-2.6.4.jar http://central.maven.org/maven2/com/fasterxml/jackson/core/jackson-core/2.6.4/jackson-core-2.6.4.jar
wget -O jackson-databind-2.6.4.jar http://central.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.6.4/jackson-databind-2.6.4.jar
wget -O jackson-annotations-2.6.4.jar http://central.maven.org/maven2/com/fasterxml/jackson/core/jackson-annotations/2.6.4/jackson-annotations-2.6.4.jar
wget -O slf4j-api-1.7.13.jar http://central.maven.org/maven2/org/slf4j/slf4j-api/1.7.13/slf4j-api-1.7.13.jar
wget -O slf4j-simple-1.7.13.jar http://central.maven.org/maven2/org/slf4j/slf4j-simple/1.7.13/slf4j-simple-1.7.13.jar
sarxos commented 8 years ago

@mambrus, I will change project POM to produce downloadable ZIP with all dependencies and ryzom-network-client JARs included. This IMO is better option then downloading every one manually and managing dependencies list in two places (in POM and README or wiki).