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

Question: How to start web console with non-core lib #110

Closed
saikrishna321 opened this issue Dec 3, 2016 · 11 comments
Closed

Question: How to start web console with non-core lib #110

saikrishna321 opened this issue Dec 3, 2016 · 11 comments

Comments

@saikrishna321
Copy link

saikrishna321 commented Dec 3, 2016

@albertlatacz i have used java-repl for building my project for testing purpose, and wanted to embed it into web by starting the jar which i have build

for ex: java -jar appiumrepl.jar from command line

If i embed the iframe for webconsole which is provided that gets the java-repl.jar by default, instead i want the webconsole to start with the jar which i build..

any help on this ?

@albertlatacz
Copy link
Owner

albertlatacz commented Dec 4, 2016

This has improved from version 415.

You can now add multiple expressions (one per line) into javarepl.init file in current directory, for example:

./javarepl.init

:cp http://repo1.maven.org/maven2/joda-time/joda-time/2.9.6/joda-time-2.9.6.jar
:cp http://repo1.maven.org/maven2/com/javarepl/javarepl/415/javarepl-415.jar

then you can also add --expression flag when starting JavaREPL to pass single expression:

$ java -jar build/libs/javarepl-dev.jar --expression="name = \"Java REPL\""

should output

screen shot 2016-12-04 at 09 20 13

@saikrishna321
Copy link
Author

@albertlatacz instead of starting the webconsole with java-repl-415.jar and then add the :cp joda-time.jar, can't we start the webconsole by adding it directly to the jar file ?

@albertlatacz
Copy link
Owner

albertlatacz commented Dec 4, 2016

Sure, it's more in a case where you don't want to embed it. Not sure if I understand what you're trying to do. Do you want to reuse web console and expose it in your app?

@saikrishna321
Copy link
Author

@albertlatacz yah your right .. i want to reuse web console and expose to ma app..

@albertlatacz
Copy link
Owner

Unfortunately it's not exposed at the moment. There is a way to connect to embedded repl. What you could do is to configure it like in javarepl.examples.EmbedInApplication and then connect command line repl with

java -jar build/libs/javarepl-dev.jar --hostname=localhost --port=8001

Hope that helps.

@saikrishna321
Copy link
Author

@albertlatacz i get the below error

~/git/AppiumJavaRepl/target (master ✘)✭ ᐅ java -jar appiumrepljava-1.0-SNAPSHOT.jar --hostname=127.0.0.1 --port 8001

:::- Appium Java REPL -:::

Enter import static com.appium.repl.Appium.*;

Enter import io.appium.java_client.*;

Enter AppiumDriver driver = driver.start(path_to_json_file in quotes)

Type driver. tab to get all appium commands

Welcome to JavaREPL version null (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_111)
ERROR: Could not connect to remote REPL instance at http://127.0.0.1:61344

@albertlatacz
Copy link
Owner

I think I understand now.

Appium bundles all libraries required, right?

So you could package them all in fat jar

build.gradle

plugins {
    id "com.github.johnrengelman.shadow" version "1.2.4"
}

apply plugin: 'java'

repositories {
    mavenCentral()
    maven { url "https://plugins.gradle.org/m2" }
}

jar {
    manifest {
        attributes 'Main-Class': 'com.javarepl.App'
    }
}

dependencies {
    compile 'com.javarepl:javarepl:417'
    compile 'joda-time:joda-time:2.9.6'
}

Then start JavaREPL like so

package com.javarepl;
import javarepl.Main;

public class App {
    public static void main(String[] args) throws Exception {
        Main.main(args);
    }
}

then after building with

$ gradle clean shadowJar

you should have javarepl-app-all.jar

then run

$ java -jar build/libs/javarepl-app-all.jar

Example project below

javarepl-app.zip

@saikrishna321
Copy link
Author

@albertlatacz this just builds the fat jar with java-repl as base. i was able to do this with ma project.All that i wanted to do is, acess the fat jar through webconsole ..

Working example:: https://github.com/saikrishna321/AppiumReplJava

mvn clean install

java -jar target/appiumrepljava-1.0-SNAPSHOT.jar

this gets the java repl, i want to access the same from webconsole

@albertlatacz
Copy link
Owner

Ahhh, yes, this would be a useful feature.

I have added a way to access local repl through web interface. Once you build as above with latest version and run you should get

screen shot 2016-12-05 at 19 31 54

and then should also be able to access the web interface

screen shot 2016-12-05 at 19 32 28

which you can then embed wherever.

@saikrishna321
Copy link
Author

@albertlatacz awesome that was quick, works well. Is there a way we can set port and hostname?

this didnt work
java -jar /Users/saikrisv/git/AppiumJavaRepl/target/appiumrepljava-1.0-SNAPSHOT.jar --port=4723

Welcome to JavaREPL version null (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_111)
ERROR: Could not connect to remote REPL instance at http://localhost:4723

@albertlatacz
Copy link
Owner

albertlatacz commented Dec 6, 2016

Ok, try version 424 including port as you were.

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

No branches or pull requests

2 participants