Packaging Electron Apps with external files - electron

In my Electron application, I have a button in which a user can click which triggers node's child_process and runs an external .jar file in the background:
exec(`java -jar encoder.jar -i filein -o fileout`, function(err, stdout, stderr)
The actual .jar file is located within the root directory of the project. When running in development mode(unpackaged) this works great. However, when I package it and run the application, I get the following error:
There was an error: Error: Unable to access jarfile encoder.jar
Am I to assume that everything in the project folder gets packaged when using electron-packager? If not, what am I missing?

look into process.resourcesPath

Related

Attempting to spawn on exe in unpacked asar results in the exe being unpacked to a temp directory?

I have an electron application that I'm packaging up with electron-builder.
Within that application there is a distribution of an exe that I want to be able to call from electron.
The build section of my package.json includes an asarUnpack property, like so:
"asarUnpack": [
"**/node_modules/dist-myexe.exe/**/*",
],
This means that when my application is installed, the exe is extracted under
C:\Program Files\MyElectronApp\resources\app.asar.unpacked\node_modules\myexe.exe\vendor\myexe.exe.
However, when I attempt to child-process.spawn on that exe, windows attempts to run a version from:
%APPDATA%\Local\Temp\par-blahblahblah\cache-blahblahblah\myexe.exe
I'm wondering if this is related to: https://github.com/electron/electron/issues/12092
Is this expected behaviour for electron apps? How can I target the exe that is in Program Files instead?
The exe I was trying to execute on was exiftool.exe, which is actually the culprit extracting to Temp, not electron.

Include non-electron folder as part of the NSIS installation

I've been trying to add additional functionality to the electron installer, where I copy some files that are packaged inside the installer, but I receive a non-descriptive error when I try to compile my electron project to create the installer i.e. I get:
* writing effective config
* packaging
* building
x [object Object]
Here is what my script looks like:
!macro customInstall
Rename "$APPDATA\myfolder\img" "$APPDATA\myfolder\img-old"
SetOutPath "$APPDATA\myfolder"
File /nonfatal /a /r "additional_files\*"
CreateShortcut "$SMSTARTUP\mylink.lnk" "$INSTDIR\mylink.exe"
!macroend
Basically everything works except the file copy part. When I remove that part the project builds and compiles into an installer with no problems.
I've also tried to use CopyFiles instead of SetOutPath and File and it works as expected when I place the additional_files folder into the same folder as the installation (dist folder), but I want the folder to be packaged inside the installer. However, I cannot get the additional_files to be packaged with the installation.
I believe it's a location issue, that is, that the NSIS script cannot locate the additional_files/ folder. I've tried modifying the package.json file by adding to the files section the additional_files/ folder and placing it in the root of the project.
I've even tried placing it in the build folder where my installer.nsh script resides, but with no luck.
File looks for files relative to the directory where the .nsi is by default. /NOCD can be used to prevent that but I'm not sure if electron uses that switch.
!cd can be used inside a script to change the directory but I'm not sure if that is going to help you much in this case unless you are willing to use a absolute path and in that case you could just use the absolute path with the File instruction instead.
If you only know where your .nsh file is I suppose you could try File /r "${__FILEDIR__}\additional_files\*"
if you are using electron-builder you have two options inside the settings
extraResources this will copy files into the $INST_DIR/resources folder in your app (this is where the app.asar file is too), and you can access via process.resourcesPath, ex:
extraResources: [
{ from: './dist/ThirdPartyNotices.txt', to: 'ThirdPartyNotices.txt' },
]
extraFiles this would do the same but place the files into the $INST_DIR root folder of your installation ex:
extraFiles: [
{ from: './distrib/mytool.exe', to: 'mytool.exe' },
],
to get the root folder you can use something like remote.app.getAppPath().replace('resources\\app.asar', '').replace('resources/app.asar', '');
all info on: https://www.electron.build/configuration/configuration#overridable-per-platform-options

javafx native package error invoking method

I'm developing a desktop application using javafx v8.0.60. I have created an exe package with ant in netbeans 8. When I run exe file in my computer, it is installed and run without any problem.
On the other hand, when I try to install and run it on some other computer, at the end of installation, window dialog pops up:
"Error invoking method"
I click Ok. Another window pop up saying:
"Failed to launch jvm"
Davood, greetings! I had this same problem and I, like you, found no help anywhere.
I submit to you a solution, which miraculously worked for me and helped me make sense of those blasted "Error invoking method." and "Failed to launch JVM" dialogs:
Find your .jar file
It has the same name as your Project and it's in your application's installation directory under AppData\Local\{ApplicationTitle}\app (shortcut: type %appdata% into explorer); if your project was named HelloWorld, there you will find HelloWorld.jar
Navigate to it's directory in command prompt
shift+Right Click any blank spot in the Explorer window and choose "Open command window here" (that's a fancy trick I recently learned; alternatively you would cd to the same directory using the command prompt)
Run your .jar via the command line
type java -jar "HelloWorld.jar" and hit Enter
Tadah! Behold your hidden exceptions (the existence of which "Error invoking method." so vaguely tries to communicate to you). *
If your problem is similar to mine it stems from a file structure difference between the project out folder and the installation directory, and that's why the program compiles just fine in the editor and builds just fine—there isn't a problem until it's built out, and the file structure is a little different.
*If you didn't get anything when you ran it via the command line, look for any errors that could be happening during that initialize() method; that's where your problem likely is. You can expose any exceptions during runtime by using a Popup Exception Dialog like shown in a similar problem, here.

'rake' is not recognized as an internal or external command, operable program or batch file

Minutes ago, I downloaded the oscurrency code from github, and I'm installing oscurrency on heroku. Everything seemed to be going perfectly until this command:
rake heroku:install
on the command line, in the directory where I downloaded the source code. I get the error:
'rake' is not recognized as an internal or external command, operable program or batch file.
I'm following the installation instructions at heroku here:
https://github.com/oscurrency/oscurrency/wiki/Heroku-Deployment-Guide
The command "rake heroku:install" is in the third paragraph from the bottom.
The code I downloaded came in a top-level folder called oscurrency. I downloaded that onto my laptop in C:\me\oscurrency. I was issuing the command in that directory when I got the error. I tried issuing the command in the folder C:\me\oscurrency\oscurrency -- same error.
Maybe the command has changed for some reason. Anybody have an idea what's going wrong?
Your problem is most likely that the command prompt is looking for a file named rake.exe and not able to find it because your PATH environment variable is not set to include that directory. I suspect that the rails command won't work either. You should add the ruby install directory (probably C:\Program Files\Ruby on Rails\bin\ to your PATH environment variable.
To do this, open your Computer Properties by right-clicking My Computer and selecting Properties, then find the "Advanced System Settings" link. Click the "Environment Variables" button at the bottom, and paste the path to that directory into the PATH variable, separating it with a semicolon.

how to compile java files classnotfoundexception

I am having a java project having the directory structure as
java->applet and a few .java files
the applet folder further contains two folders and some .java files
I need to develop a jar file out of this project
I did so by writing the command line
jar cvfm myfile.jar *.java
(obviously by moving into corresponding directory)
when I checked by extracting the file(it was zipped as a Nokia application installer file)
it showed me only the classes in the applet folder not the folders in it
moreover i needed to use this jar file in a jquery plugin where i had written
var dasherApplet = $('applet');
dasherApplet.attr({
'height':'100%',
'width':'100%',
'archive':farfalla_path+'plugins/dasher/jardasher.jar',
'code':'JDasherApplet.java'
});
but it showed me the class not found exception
for this I checked the previous versions of the java applet; there the java files were replaced by .class files so i tried compiling a java file into .class by using the command line
C:/>javac filename.java
still all in vain this time it showed me
"cannot find symbol" error
what was interesting was that the errors generated were imitating the java files present in the same folder. I navigated to the directory where the file was stored still the same error
when i tried to simply run it by using
java filename.java
error was main class not found:JApplet.java
Please help me develop this applet
Firstly you need to compile all the jar files before running.
Secondly , you CANNOT run Applets using java filename.java .
As this link explains http://download.oracle.com/javase/tutorial/deployment/jar/build.html ,
jar cvf TicTacToe.jar TicTacToe.class audio images
Here audio and images are folders , so that is how you add folders to jar.
Also .jar files are not Nokia Application Installer files . Nokia simply associates them for installing apps (that is J2ME)

Resources