How can I implement a maven dependency into my nodejs code? - node.js

My backend server is implemented by nodeJS.
Now, I need to add a new feature and a maven dependency is required according to the related document.
The document just says:
//Add dependency
<dependency>
<groupId>com.COMPANY.A</groupId>
<artifactId>SOME-NAME</artifactId>
<version>1.0.0</version>
</dependency>
But my code is written in NodeJS, so I wonder how I can insert this dependency setting into my code.
Any comment or link that I can refer to is appreciated.

AFAIK there is no way to import Maven dependency to NodeJS code. NodeJS does not support running uncompiled Java code.
If your dependency has a Main class, you can download the Jar from JCenter and run it as follows:
const execSync = require('child_process').execSync;
const output = execSync('java -cp ./SOME-NAME-1.0.0.jar com.foo.MyMainClass');

Related

Using cucumber with cypress

Can anyone help me getting Cucumber to work with Cypress? Absolutely every guide I can find has this step in the setup:
X.
Add the relevant configurations to your Cypress environment files accordingly.
Under plugins/Index.JS file add the following:
const cucumber = require('cypress-cucumber-preprocessor').default
module.exports = (on, config) => {
on('file:preprocessor', cucumber())
}
However, my project doesn't HAVE a cypress/plugins/index.js file. It DOES, however, have a cypress/plugins/index.ts file. I thought TypeScript was the going standard for Cypress, and not JavaScript?
The code above gives me errors on "require" (TS2591: Cannot find name 'require'), "module" (TS2591: Cannot find name 'module') and the parameters "on" and "config".
Apparently, the index.ts file WAS index.js once, since this is still included in the file:
// This example plugins/index.js can be used to load plugins
But obviously something is wrong here. But how come apparently no one else on the "entire internet" have had this problem? ( :-) )
To keep on trying, I skipped this part - also since I read some hints that it isn't longer necessary (not sure, though).
I also added this dependency to the project pom.xml:
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-cypress</artifactId>
<version>5.7.0</version>
</dependency>
Then did the npm installs, maven clean install, refresh etc. etc., and creted a test.feature file in the /integration folder.
It seems that IntelliJ reconizes the file as a Cucumber feature file, because I get the option to run both the feature and the test inside.
However, that just gives me the following error when the feature tries to run:
Error: Could not find or load main class cucumber.cli.Main
Caused by: java.lang.ClassNotFoundException: cucumber.cli.Main
Figuring it was due to the cucumber.cli.Main missing in the run config, I opened it and saw that it wasn't. Nor was it working:
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/ib9ZT.png
(The "cucumber" part of the line is makred red in "Main class".)
Changing this to " io.cucumber.core.cli.main" (which I believe is newer?) didn't help.
The last step I've tried is installing the Cucumber Js plugin in the plugin browser. Didn't seem to do any difference.
I'm afraid to try much more, since in my experience messing around too much with maven is likely to ruin any project to the point of me just having to scratch it and start over again.
Have you looked at https://github.com/TheBrainFamily/cypress-cucumber-typescript-example/?
It seems that you can use Cypress in Typescript but still define the plugins with JavaScript. That is you should convert your plugins.ts to plugins.js and everything should work as expected.
When you mentioned pom.xml, it must mean you are trying to set up Cypress and run in a Maven build.
You should first set up Cypress the node.js way first using npm install -D cypress#<an older version> because npm i -D cypress will install cypress 10 for you. Then after that, follow the steps in the link shared by #https://stackoverflow.com/users/5389127/ga%c3%abl-j to set up Cucumber for the older versions of cypress but use this for the later version of cypress.
You can set the repo up in maven using this article in this answer.
For a comprehensive guide on how to use Cypress, you can checkout this youtube link

OpenAPI java generated client Class not found error

I have an issue with OpenAPI generator for Java client.
I am using nodeJs openApi generator to generate a Java api client with :
npx openapi-generator generate -i .\swagger.yaml -g java -o ./output -c config.yaml
then use mvn package to package the output and integrate it to my spring-boot application.
My problem appears everytime I try to create an instance of my api. I get this error :
Caused by: java.lang.NoClassDefFoundError: io/gsonfire/GsonFireBuilder
I checked to generated pom and I can see that the dependencies are there:
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson-version}</version>
</dependency>
<dependency>
<groupId>io.gsonfire</groupId>
<artifactId>gson-fire</artifactId>
<version>${gson-fire-version}</version>
</dependency>
Thanks

How to test code dependent on environment variables using JUnit mockito?

I am trying to add import "org.junit.contrib.java.lang.system.EnvironmentVariables;" but getting error This(org.junit.cont....) import cannot be resolved. I added below dependency:
<dependency>
<groupId>com.github.stefanbirkner</groupId>
<artifactId>system-rules</artifactId>
<version>1.2.0</version>
<scope>test</scope>
</dependency>
any other way to set environment variable using junit mockito.
Can i set the env variable using powermock ?
Use a newer version, like 1.19.0.
I am not sure when the class was introduced, but its later than 1.2.0.
Edit:
The GitHub list a change date of May 18, 2018, so it should be at least
1.18.0.

Spark Error: Could not initialize class org.apache.spark.rdd.RDDOperationScope

I've created a spark standalone cluster on my laptop,
then I go into an sbt console on a spark project and try to embed a spark instance as so:
val conf = new SparkConf().setAppName("foo").setMaster(/* Spark Master URL*/)
val sc = new SparkContext(conf)
Up to there everything works fine, then I try
sc.parallelize(Array(1,2,3))
// and I get: java.lang.NoClassDefFoundError: Could not initialize class org.apache.spark.rdd.RDDOperationScope$
How do I fix this?
maybe you missed following lib.
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.4.4</version>
</dependency>
this error message is usually accompanied by
Cause: com.fasterxml.jackson.databind.JsonMappingException: Incompatible Jackson version: 2.9.8
it means there are conflict versions in the dependencies (obviously). in the Spark world, usually it is because some lib we use has dependency conflict with spark shipped one.
use coursier resolve can find out what's happening. (gradle also has debugging dependency.
cs resolve org.apache.spark:spark-core_2.11:2.4.5 | grep jackson
cs resolve com.thesamet.scalapb:scalapb-json4s_2.11:0.10.0 | grep jackson
then either build a uber jar for our application, or excluding the conflict in the build (if it is possible). e.g. build.gradle
testCompile 'com.thesamet.scalapb:scalapb-json4s_%%:0.10.0', { exclude group: 'com.fasterxml.jackson.core' }
Adding the following jar to the Bin folder of the spark if you using spark console.
https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind/2.9.9.3

How do I install a required package on IBM Bluemix when deploying a Meteor application from DevOps Services?

I hope there is an IBM Bluemix wizard watching that can answer this.
I have an application, written in Meteor, which I am trying to deploy to Bluemix. The application contains this line:
var AdmZip = Npm.require('adm-zip');
which of course means that the application uses the adm-zip package to do stuff. When I try to deploy the application via DevOps Services, it fails with this error:
ERR Error: Cannot find module 'adm-zip'
in the logs. If I remove the Npm.require line, the application deploys fine, but of course doesn't work correctly because adm-zip is not there.
My package.json file contains, among other things, this entry:
"dependencies": {
"adm-zip": "*"
},
which I believe should be sufficient to load the adm-zip package. I've also tried specifying a Git URL for adm-zip but the results are the same.
Does anyone know what I have to do to get this application to deploy correctly?
Looking at the Meteor documentation the following line...
// import a global NPM package
var Spooky = Npm.require('spooky');
...tries to import a global NPM package (installed with the -g flag).
There is a plugin for Meteor that handles NPM integration.
Install this module with the following command:
$ meteor add meteorhacks:npm
If you have correctly set up the package dependency in package.json, you can use the following to import and use the spooky package:
// This method loads NPM modules you've specified in the packages.json file.
var Spooky = Meteor.require('spooky');

Resources