how to run .jar files on Synology - java

for a Synology NAS DS118 i want to run a jar file and i'm looking for a way to hibernate the program on the synology so that it executes automatically, can anyone help ?
i have tried to run the .jar from the ssh client but i think i should first make the jar file executable and i still didn't figure it out...i couldn't find any detailed tutorials yet :( –

You have to installed and updated the Oracle Java package. You have to also enable terminal access to the NAS and navigated to the right directory where the jar file is. I am not aware of your specific package, but i assume since you can start the foo.jar via double click you might also be able to start this foo.jar on your DiskStation like this :
ssh -ladmin YOURDISKSTATIONIP
YOUR_ADMINPASSWORD
cd TOYOURJARDIRECTORY
java -jar foo.jar
where foo.jar is the .jar you want to start.
You can write a bash service and it gonna be automatized. I hope it will be helpful for you.
To make your java file executable. See this post;
https://stackoverflow.com/a/47209860/5879876

Related

How to make my jar file executable by double click to open terminal

Okay so basically, every time I've seen this question asked it doesn't have the answer I'm looking for which is why I'm trying to ask myself.
Basically, I made a java project on BlueJ (required by school, sadly. But I can export it elsewhere if that's the problem (preferably IntelliJ or Visual Studio Code)), but essentially, I want to make it so I can simply double click my .jar export and it will open a terminal window and launch. When I try this however, I get this error: First Error
And when I click Ok then this appears:
Second Error
Now, if I want the jar to run on terminal, doing java -jar jarFileName.jar works perfect, but what I want is for that to happen when I double click the jar file; for it to launch and run from the terminal.
All the other answers I've seen for this problem blame the users computer and usually tell them to install some version of java or whatever, but this isn't the problem. I have other jar files that I can run perfectly fine, like Minecraft Forge installer or Minecraft Spigot installers (sorry only examples are Minecraft, not much else uses Java). And also this was for a uni project and no one else in my field know how to get their jar to be executable, nor does this file work for anyone else.
So yeah, I know it's a problem with how the jar was compiled or something and not what java is installed my PC.
I just want to make it double-clickable for the convenience of when I send it to friends, but if anyone knows another way I can get around this problem then that's fine. For example I know I could make a Bash file which simply does the java -jar jarFileName.jar for me or something, but I'd rather have it all as one jar file, so I don't know if this can be incorporated into the file but yeah.
Also I'd really like a solution which doesn't involve downloading external programs or whatever, since all I want to do is send this file to my friends and have them just double click it to launch.
TL;DR, what do I have to do to make my jar file actually executable by double clicking it. Thank you.
To make a jar file executable you have to set the entrypoint
You can do this by passing the e option to the jar command when you create the jar file, for example:
jar cvfe myapp.jar com.mycompany.myapp.MyApp com\mycompany\myapp
This will add the Main-Class entry in the jar's manifest pointing to the startup class, which should have a main method, for example:
package com.mycompany.myapp;
public class MyApp {
public static void main(String[] args) {
// start up the application
}
}
When you create a JAR file, it automatically receives a default manifest file. There can be only one manifest file in an archive, and it always has the pathname
META-INF/MANIFEST.MF
The entrypoint is specified by the Main-Class, for example:
Manifest-Version: 1.0
Created-By: 1.8.13_37 (Oracle Corporation)
Main-Class: com.mycompany.myapp.MyApp
If you want to make an existing jar file executable you could unzip it, modify the manifest and zip it again (and rename it so it has the .jar extension - a jar is just a zip).
But I think the errors you show are not caused by the jar not being executable, but by some environment issue, causing the Java application to not find the necessary variables or paths to make the Java Native Integration (JNI) work. To solve this you would have to provide more detail on what you are trying to do with JNI.

Making a Java application for Mac users

I succesfully generated a dmg file thanks to this question. My issue now is that when I open the .app file, the program starts and immediately stops.
1) On Mac, how can I get the java error if any?
2) I think that the error occurs because the .app cannot access the files that are within the dmg. The same answer indicates that I could add my files to the .app file. I can do that, but then, how am I supposed to access these files from my application? What would be the path I should use?
3) For GNU/Linux and Windows users, I currently have a .jar file that updates my application by updating the myapp.jar file and some other files. If everything is packaged into the myapp.jar file, how am I supposed to do that?
Thanks for you help!
Have not tested the following but based on what’s described at Bundle Java program for Mac users with maven from GNU/Linux, the following are the steps I would try.
Open Terminal and cd to whatever directory .app is in.
Run find . -name java.
That will return something like foo/bar/jre1.8.0_112.jre/bin/java I guess.
Run find . -name myapp.jar where myapp.jar is the name of the jar you made.
That will return something like foo/bar/myapp.jar.
Run foo/bar/jre1.8.0_112.jre/bin/java foo/bar/myapp.jar.
If that runs, some error message will get emitted that should explain what else is not working.
Note that you can change files inside that .app directory; specifically, you can replace the jar file within the directory.

How to run or call an exe file from a JAR file which is present in the same directory?

Hello all :) I love stackoverflow where I always find answers but this time I could not so personally asking... Its bit lengthy please go through it.
I am creating a java application where one of my resource is an exe file which I need to call in the java code. But later I would convert the whole java code to a JAR file... and I would add the JAR file and the exe file for the Setup file for installation process. So when I extract the files I want my JAR file to call the exe file while running... I am doing this all in Eclipse :)
So my doubt comes here which path I should put up in the java code... ? So that it will always call the file the exe file from the same directory where the JAR file is also present.. :)
Any help would be great :) Thank you in advance :)
Assuming that you control the whole installation process; and that you also control the script that later starts a JRE to run your JAR within; my suggestion would be: simply use a property here.
In other words; your installer knows that it copied JAR and EXE to D:\example\ for example. Then just make sure that your JAR is started like:
java -jar D:\example\your.jar -D your_path=D:\example
(this is just meant as example, you would have to work that out, probably the \ in there need some special treatment for example)
Then your application can simply query for that system property "your_path" and take the value from there.
Alternatively, you could try this solution that works "pure java".

Executable Jar file not working another machine

I have created an executable jar file to my java programm using Eclipse(File->Export).
When i double click the jar it works fine.After i copy the jar file to another machine(windows) i got an error "Invalid or corrupt jarfile".I have installed JRE and JVM.
Anybody know what is the issue.
Help is highly appreciated.
Thanks,
vks
as you said you have double click
try command line as another machine(windows) might not be assign jar extension to execute.
to run jar manually do.
java -jar example.jar

Unable to create jar file from console and program don't work rigth after building with IntelliJ

I try to learn how to inject bytecode in java with javassist and java agents so I started (http://appcrawler.com/wordpress/2013/01/02/simple-byte-code-injection-example-with-javassist/) << this tutorial I've copied the most of the code and read it to understand it that worked more or less.
But when the tutorial said I should create an jar file with this command
jar cvfm myAgent.jar mymanifest.txt SimpleMain.class SimpleTransformer.class
I tried to write this into my CMD console (hope that was rigth...) and it always tells me an error that he can't finde the command "Jar" so I googled the error and google said i should try
java -jar cvfm myAgent.jar mymanifest.txt SimpleMain.class SimpleTransformer.class
and this said "unable to acces jarfile cvfm"
Ok. After that I tried to create a jarfile with IntelliJ, but that didn't do what it should either. It don't even run the pre-main method so if the console command would work rigth it would be a nice start and if you guys can than help me do run the code rigth that would be awesome!
You're first command line was correct. It's just that the jar exectuable was not on your path ( I'm going to assume you're on windows. )
You should first, make sure you have the JDK instead of the JRE installed, and follow the oracle installation instructions.

Categories