Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Executing Faker.js in Java

 
Peter Srnec
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys!

I have a small problem with execution of js code in Java.
My goal is to use this js faker API https://github.com/marak/Faker.js/ and call its methods in Java.



If I use the code above, it will crash on:
javax.script.ScriptException: TypeError: Cannot set property "faker" of undefined in src/com/test/faker/faker.js at line number 1

I think this shouldn't be a problem on my side, but with that js faker code which cannot be loaded properly in java script engine.
Can anyone give me a hint what is causing this error and how to fix it?

PS: as you can see, I'm not a good friend with js
 
Tim Moores
Saloon Keeper
Posts: 3266
55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I took a quick look around Github, but didn't see a script "faker.js". Can you provide a direct link? It's hard to even speculate what might be going on without seeing the actual JS code.
 
Campbell Ritchie
Marshal
Posts: 52625
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
Nigel Browne
Ranch Hand
Posts: 703
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Moores wrote:I took a quick look around Github, but didn't see a script "faker.js". Can you provide a direct link? It's hard to even speculate what might be going on without seeing the actual JS code.


Direct link to faker.js
 
Tim Moores
Saloon Keeper
Posts: 3266
55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a big file! I think my first advice would be to try it with a much smaller version (maybe 10% in size), and thus to make sure the failure isn't caused by the file size.
 
Dave Tolls
Ranch Hand
Posts: 2286
25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd break up that first line.
It's a monster.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!