What are the minimum unix permissions to run an executable jar file? - java

If I have a jar that I need to run using java -jar FOO.jar on unix, does this depend on the read, write or execute bit? Or some combination thereof?

You just need read on the .jar, since java is what you're executing, and it reads the jar.

You will need read, since the jar is virtually executed by java (of course java needs to have exec permissions). But if you have a program that stores some data inside itself (it can happen, for example storing settings) I would suggest to have also the write attribute set.

Related

Run jar file with arguments without having to use command line

I am using Alpn-boot to add support for HTTP.2 requests using OkHttp. In order for that to work i always have to launch my compiled jar file through the command line and specify the path of alpn-boot.jar file with a <-Xbootclasspath> argument :
java -jar -Xbootclasspath/p:<path_to_alpn-boot.jar> <path_to_myjar.jar>
Is there anyway to avoid this, and make the jar run with the -Xbootclasspath argument specified by default?
Edit: I thought about using a batch file to do this, but is there no other native way?
Batch file is convenient and standard enough. Unless you have specific reason not to use batch file, batch file would do it

How to execute a jar executable file and receive the return value

Assume that I have a java program A. The Java program A needs to call another java program B(jar), passes arguments to it and receives the return value from B. How can I achieve this?
The easiest solution would be to have the jar as a build-time dependency and invoke it statically from your code.
Please check this: How to run a jar file from a separate jar file?
The above is more applicable for you compared to Execute another jar in a java program
I believe your question is answered here Execute another jar in a java program depending on your runtime environment you may need to specify a path to java and/or the jar file
All we have to do is introduce an entry into the JAR file's manifest (MANIFEST.MF in the JAR's META-INF subdirectory), like
Main-Class: com.tedneward.jars.Hello
All a user has to do to execute the JAR file now is specify its filename on the command-line, via java -jar outapp.jar.

How to write a SVN pre-commit hook script in Windows(Server-side)

Each change made and committed to SVN by a developer on my team delivers a requirement of the app and this requirement has an id which is written in the first line of the commit message.
I need a hook to catch this id and call an external service to verify if the id status is OK. I have read a lot about SVN structure and hooks but don´t understand how to write this hook in Java.
A hook is is just a executable program placed in a specific place that accepts specific arguments. What language it is in doesn't really matter.
In your case if you're trying to write it in Java and run it on Windows you probably need to write a .bat file and install it as under the hooks directory with the proper name. You'll need to pass through the arguments the batch file receives to your java program.
The reason you'll need a batch file here is because Windows can't just start a Java program for you and you need to run Java with the proper arguments.
Something like this should work:
#echo off
java -jar myjavahook.jar %*
The %* copies all the arguments to the batch file and adds them to your java program.
You may need different or additional arguments depending on your Java program.
Since you're writing a pre-commit hook and the exit code of the batch file is important you'll probably also want to do something like this what is described in this other question:
Can a batch file capture the exit codes of the commands it is invoking?

build multiple shared libraries

Hi I have a java program which has to invoke a native program, and this native program are given by two so files. So I create my so file in order to use this native program APIs to do something for my java program. I was trying to merge two so files with my created so file into single one, and run my java program. However, it seems that it failed this way. To be more concrete, here is my example.
I have a java program A which has to invoke some native code. Therefore I've written some native code and built it as a shared library (called: C.so).
Unfortunately, the native code I've written have to use other code which is in other so files. (A.so, B.so)
Thus, any ideas how to compile my so file with A.so and B.so in order to make my java program work?
I'm assuming the following:
When you link c.so, you are listing a.so and b.so on the command line.
When you run ldd on c.so, you see a.so and b.so.
When you run, you set -Djava.library.path to include the directory containing all three.
When you run, you do NOT set LD_LIBRARY_PATH to include the directory containing all three.
You will get the desired results if you set the LD_LIBRARY_PATH environment variable to include the directory with the libraries in it.
For more explanation, and an alternative, see https://github.com/bimargulies/jni-origin-testbed.

I need a solution to starting Slick 2D/LWJGL Java project via command line. Help?

Currently I am starting my Slick 2D application via this batch file-
java -Djava.library.path=lib -Xms512m -Xmx512m -jar myapp.jar %1
Where lib is the folder that contains the LWJGL/Slick libraries and myapp.jar is my application.
Although this is easy and effective I want to be able not to have to run a script all the time and actually create a java .jar to do this.
So my question is, how would I 'convert' this batch script into Java code?
Why you would want Java code for this is beyond me as that creates exactly the same problem for you again – namely running your startup Java program that then starts another Java program; you'd be at the same point as before.
However, you don't need to create a JAR in any case. You can stuff all your compiled .class files somewhere and set that as the classpath. A JAR is little more than a main class and a classpath bundled into one.
So instead of your invocation above you can then use
java ... -cp %USERPROFILE%\Java\MyApp myapp.gui.Main
or something like that. Set the classpath with -cp and give the main class on the command line instead of the JAR.
Any -D command line arguments can be set via java.lang.System.setProperty. But the memory parameters can't be set from inside a JVM as far as I know. Therefore, there is no way to do what you want.
Instead you could generate e.g. a Windows executable with JSmooth. Such a wrapper should be able to set all JVM arguments. But in the end the situation is similar to the script. You have some kind of wrapper.
The easiest way is to use a program like JarSplice (http://ninjacave.com/jarsplice)
You can easily create a jar executable with all needed lib. it works very well

Categories

Resources