error when using the import java class
Hi everyone,
I have a java dependency that I need to add to my nodeJS application. I manage to run all the commands in the tutorial and my code look like this:
var java = require("java");
java.classpath.push("commons-lang3-3.6.jar");
java.classpath.push("commons-io-2.4.jar");
var ArrayList = java.import('java.util.ArrayList');
var list3 = new ArrayList();
I can see that I manage to add my project dependencies to it.
Any ideas of what can be wrong?
My log doesnt show much.
Code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] test-chrome-local: `node node_modules/webdriverio/bin/wdio ./test/config/suite.local.chrome.conf.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] test-chrome-local script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/dkrechwa/.npm/_logs/2018-04-20T12_30_15_377Z-debug.log
Im running this code on my test suite, but is just executing a .js file, nothing much
Hi everyone,
I manage to make it work with the import java.lang.System' and java.util.ArrayList
but still not able to make it work with my own .jar even the ones used on the examples folder.
java.classpath.push("lucene-core-6.0.0.jar");
java.classpath.push("lucene-analyzers-common-6.0.0.jar");
java.classpath.push("lucene-queryparser-6.0.0.jar");
var idx = java.newInstanceSync("org.apache.lucene.store.RAMDirectory");
Im getting this error:
var idx = java.newInstanceSync("org.apache.lucene.store.RAMDirectory");
^
Error: Could not create class org.apache.lucene.store.RAMDirectory
java.lang.NoClassDefFoundError: org/apache/lucene/store/RAMDirectory
Caused by: java.lang.ClassNotFoundException: org.apache.lucene.store.RAMDirectory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at Object.<anonymous> (/Users/dkrechwa/Documents/Workspace/GitLab/com-lego-global-flipper/jar/teste.js:20:16)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3
Make sure you add everything to the classpath before calling anything else in node-java. Also take a look at https://www.npmjs.com/package/node-java-maven I created this to easy the use of dependencies.
Hi @joeferner, thank you for the help. The only issue i'm having is that my repo is locally (I have a local gitlab), i add the repository on the index.js but i'm getting an error 401 (Unauthorized because the password and user).
Do you know if I can call the ./node_modules/.bin/node-java-maven pointing to another settings.xml adding a user and password for it ?
Currently it only supports non-authenticated access. I've had that on my backlog of things to do for some time. It will look locally in .m2/repository first so if you have the dependencies local it should work, not sure the best way to bootstrap the .m2/repository until I get reading the settings.xml in though.
One of the reasons I mentioned the route of using node-java-maven is that Java happily ignores jars it can't find in the classpath. So one option might be to specify the full path of your jars to start just to make sure.
@joeferner Thank you for the reply !!
Im adding the java.push with the full path now, but I get an error everytime I try to instantiate a method.
Sorry to bother you again but do you mind checking if I missing something on the .js code ? ?
#!/usr/bin/env node
var java = require('java');
java.classpath.push("/Users/renan/Documents/Workspace/GitLab/projeto/jar/eyes-selenium-java3-3.29.jar");
console.log("CLASSPATH APP --- " + java.classpath + " --- CLASSPATH APP");
var eyes = java.newInstanceSync("com.applitools.eyes.selenium.Eyes");
eyes.checkWindow(5, "teste");
Log:
CLASSPATH APP ---/Users/renan/Documents/Workspace/GitLab/projeto/node_modules/java/commons-lang3-node-java.jar,/Users/renan/Documents/Workspace/GitLab/projeto/node_modules/java/src-java,/Users/renan/Documents/Workspace/GitLab/projeto/jar/eyes-selenium-java3-3.29.jar --- CLASSPATH APP
/Users/renan/Documents/Workspace/GitLab/projeto/jar/teste2.js:9
var eyes = java.newInstanceSync("com.applitools.eyes.selenium.Eyes");
^
Error: Could not create class com.applitools.eyes.selenium.Eyes
java.lang.NoClassDefFoundError: com/applitools/eyes/EyesBase
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
Caused by: java.lang.ClassNotFoundException: com.applitools.eyes.EyesBase
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 12 more
Checking the classes on .jar
jar dkrechwa$ jar tf eyes-selenium-java3-3.29.jar
META-INF/
META-INF/MANIFEST.MF
com/
com/applitools/
com/applitools/eyes/
com/applitools/eyes/selenium/
com/applitools/eyes/selenium/capture/
com/applitools/eyes/selenium/exceptions/
com/applitools/eyes/selenium/fluent/
com/applitools/eyes/selenium/frames/
com/applitools/eyes/selenium/positioning/
com/applitools/eyes/selenium/regionVisibility/
com/applitools/eyes/selenium/triggers/
com/applitools/eyes/selenium/wrappers/
com/applitools/eyes/selenium/AppiumJsCommandExtractor.class
com/applitools/eyes/selenium/BordersAwareElementContentLocationProvider.class
com/applitools/eyes/selenium/capture/EyesWebDriverScreenshot$1.class
com/applitools/eyes/selenium/capture/EyesWebDriverScreenshot$ScreenshotType.class
com/applitools/eyes/selenium/capture/EyesWebDriverScreenshot.class
com/applitools/eyes/selenium/capture/EyesWebDriverScreenshotFactory.class
com/applitools/eyes/selenium/capture/FirefoxScreenshotImageProvider.class
com/applitools/eyes/selenium/capture/FullPageCaptureAlgorithm.class
com/applitools/eyes/selenium/capture/ImageProviderFactory.class
com/applitools/eyes/selenium/capture/SafariScreenshotImageProvider.class
com/applitools/eyes/selenium/capture/TakesScreenshotImageProvider.class
com/applitools/eyes/selenium/capture/WebDriverScreenshot.class
com/applitools/eyes/selenium/ContextBasedScaleProvider.class
com/applitools/eyes/selenium/ContextBasedScaleProviderFactory.class
com/applitools/eyes/selenium/exceptions/EyesDriverOperationException.class
com/applitools/eyes/selenium/exceptions/NoFramesException.class
com/applitools/eyes/selenium/Eyes$1.class
com/applitools/eyes/selenium/Eyes$2.class
com/applitools/eyes/selenium/Eyes$3.class
com/applitools/eyes/selenium/Eyes$4.class
com/applitools/eyes/selenium/Eyes$5.class
com/applitools/eyes/selenium/Eyes$6.class
com/applitools/eyes/selenium/Eyes$7.class
com/applitools/eyes/selenium/Eyes$WebDriverAction.class
com/applitools/eyes/selenium/Eyes.class
com/applitools/eyes/selenium/EyesSeleniumUtils.class
com/applitools/eyes/selenium/fluent/FloatingRegionBySelector.class
com/applitools/eyes/selenium/fluent/FrameLocator.class
com/applitools/eyes/selenium/fluent/IgnoreRegionBySelector.class
com/applitools/eyes/selenium/fluent/ISeleniumCheckTarget.class
com/applitools/eyes/selenium/fluent/ISeleniumFrameCheckTarget.class
com/applitools/eyes/selenium/fluent/SeleniumCheckSettings.class
com/applitools/eyes/selenium/fluent/Target.class
com/applitools/eyes/selenium/frames/Frame.class
com/applitools/eyes/selenium/frames/FrameChain$1.class
com/applitools/eyes/selenium/frames/FrameChain.class
com/applitools/eyes/selenium/positioning/CssTranslatePositionMemento.class
com/applitools/eyes/selenium/positioning/CssTranslatePositionProvider.class
com/applitools/eyes/selenium/positioning/ElementPositionMemento.class
com/applitools/eyes/selenium/positioning/ElementPositionProvider.class
com/applitools/eyes/selenium/positioning/FirefoxRegionPositionCompensation.class
com/applitools/eyes/selenium/positioning/ImageRotation.class
com/applitools/eyes/selenium/positioning/NullRegionPositionCompensation.class
com/applitools/eyes/selenium/positioning/RegionPositionCompensation.class
com/applitools/eyes/selenium/positioning/RegionPositionCompensationFactory.class
com/applitools/eyes/selenium/positioning/SafariRegionPositionCompensation.class
com/applitools/eyes/selenium/positioning/ScrollPositionMemento.class
com/applitools/eyes/selenium/positioning/ScrollPositionProvider.class
com/applitools/eyes/selenium/regionVisibility/MoveToRegionVisibilityStrategy.class
com/applitools/eyes/selenium/regionVisibility/NopRegionVisibilityStrategy.class
com/applitools/eyes/selenium/regionVisibility/RegionVisibilityStrategy.class
com/applitools/eyes/selenium/SeleniumJavaScriptExecutor.class
com/applitools/eyes/selenium/StitchMode.class
com/applitools/eyes/selenium/triggers/EyesKeyboard.class
com/applitools/eyes/selenium/triggers/EyesMouse.class
com/applitools/eyes/selenium/wrappers/EyesRemoteWebElement.class
com/applitools/eyes/selenium/wrappers/EyesTargetLocator.class
com/applitools/eyes/selenium/wrappers/EyesTouchScreen.class
com/applitools/eyes/selenium/wrappers/EyesWebDriver.class
META-INF/maven/
META-INF/maven/com.applitools/
META-INF/maven/com.applitools/eyes-selenium-java3/
META-INF/maven/com.applitools/eyes-selenium-java3/pom.xml
META-INF/maven/com.applitools/eyes-selenium-java3/pom.properties
Hi, I am also facing same issue. Error:Could not create class org.apache.tika.Tika Please,Help me with this issue. Thanks Azam