Running an uploaded executable Java program with script - java

I have a simple .sh script, which runs a Java program:
#!/bin/bash
java -jar Test.jar
However, the Test.jar is referencing a .jar file in the folder. I would like to know, whether it's possible to execute a file, that has been previously uploaded to a website. Reason: The script is sent onto (and then ran from) a server, to which I do not have access, which is why I cannot upload the said .jar file onto it.
I've tried with wget, but that command only downloads the file, rather than uses the said file in the script.

What about
#!/bin/bash
wget http://server/Test.jar
java -jar Test.jar

Related

Convert java (with params) to exe

Using Eclipse I've created a Java project with one single class that needs an argument.
In my PC where I have Java installed, I run this:
java -jar test.jar %arg1%
I can put this in a batch file and it runs successfully. The batch has the next lines:
echo off
set /p arg1=Enter path where file is:
java -jar test.jar %arg1%
pause
How can I generate this but in an exe file?
I need that the exe file ask for a path and execute the jar even thought the PC doesn't have Java
P.D. In some forums it's suggests to use launch4j but it doesn't allow dinamical params.

Running Script on Startup

Essentially what I'd like to achieve is add a .jar file to the startup of my Linux computer. I created a script that would run the file and then tried adding that script to run when the system boots up.
I have a .java file on my desktop named Box.java. The file contains no errors and I manually compiled it and it was working fine. I then created a script on my desktop called start.sh and it's contents are
#!/bin/bash
javac /home/maple/Desktop/Box.java
So what this should do is compile the java class and the result would be a class file on my desktop called Box.class
I then created a file in /etc/init.d/ and it is called **start_java* it's contents are
#!/bin/sh
home/maple/Desktop/start.sh
I then opened up terminal and did
chmod +x /etc/init.d/start_java
I know the sh file will compile a java file and not run a file, in the completed copy I will be doing it with a jar file. How can I add that jar to startup without using a 3rd party software or any pre-installed programs?
EDIT: The current way I have it is not working.
You just want to do the same thing you already did, but changing the content of start.sh to:
#!/bin/bash
java -jar <filename>

How to reference a file from any directory

I'm having the following situation.
I have a java programm packed in a jar file. If I call java -jar myProgramm.jar everything is working fine. The file is reading some values from build.xml (ant file). This file is in the same directory where myProgramm.jar is located.
In our company we wrap everything in shell scripts to have a uninfied way to call our scripts.
So my shell script myProgrammWrapper.sh looks like this:
#!bin/bash
java -jar $(cygpath -w ~/path/to/tools/myProgramm.jar) "$#"
The cygpath command is there because the sh is executed within cygwin and otherwise the path would not be found.
The"$#" passes the arguments to the program.
Following is the problem:
Our cygwin environment has been setup in a way that I can call myProgrammWrapper.sh from every directory. But of course when I call it from any random location, the build.xml is not found.
Is there a way to reference the build.xml in the shell script. It is located in ~/path/to/tools/ ?
First I was thinking about copying the build file to the current directory and deleting it afterwards. This is working fine but has one fundamental flaw. We are working a lot with ant and have build.xml files. So if someone would execute myProgrammWrapper.sh in a directory where there is already a build.xml file. It would be overwritten.
Maybe the problem can be tackled from the Java side. Any ideas and input is appreciated.
Why not make the Bash script change the working directory to where the XML file is contained?
Try:
(cd $(cygpath -w ~/path/to/tools/) && java -jar $(cygpath -w ~/path/to/tools/myProgramm.jar) "$#")

How to create a dynamic path inside a batch file?

I created a command line program in java that will be deployed. Since it has no windows it can't be run by double clicking. I then created a batch file that will run the jar but since the program will be deployed they will have a different path than me.
How do I go from:
java -jar E:\Projects\Java\SystemFileQuery\SFSQ.jar
to:
java -jar ...\SFSQ.jar
Just deploy the SFSQ.jar file to the same directory as your batch file and then you can use
java -jar SFSQ.jar

Run java class from single command using makefile

I have a homework assignment in Java that is tested using the commands:
make
./<program_name> <arguments>
my make file compiles my java program successfully, but how can the program be run without using the command:
java <program_name>
I have investigated how to convert a .jar into an .exe but I am convinced that is not the answer I am looking for.
I believe the test is run on a Linux machine. Is there something I can include in the make file to cause the command
./<program_name>
to run a compiled java class?
Without converting the java program in a native executable file, that will be different for linux, for windows and any other platform (so you will loose Java portability), the only thing you can do is to create a launch script.
On *nix system you can create a bash script and on windows a batch script. Then in this script you have to call java <program_name>.
With the script you are now able to launch your application with a single command.
For example on unix you can create myapp.sh:
#!/bin/bash
java -classpath bin com.test.YourApp $*
and make this script runnable with command
chmod a+x myapp.sh
in this example when you write myapp.sh command you launch your Java class com.test.YourApp using the folder bin as classpath.

Categories