How To Run Jar Which Is On Web Server - java

Hi, I made two versions of executable programs: on linux and windows, which includes jre and .exe and .sh each.
While working on this, I just wondered that what if I could manage jar file on web server.
I mean, In my batch file, a jar file is executed by,
"start ./jre/bin/javaw.exe -jar ./lib/aaa.jar"
So is there any way to use "http://www.mywebserver.com/lib/aaa.jar" instead of "./lib/aaa.jar"?

Java does not let you execute a jar directly from the url due to security reasons. This would be very harmful to the system. Man in the middle attacks etc.
This being said, you could still download the jar using the url and copy it to the classpath you specified and execute it.
For instance you could write java code to download the jar file.
https://alvinalexander.com/java/edu/pj/pj010011
Or you could use curl command. Etc..

Related

how to make log files to be generated at the same location as jar file

I am using jsch channelexec to call .sh file. The content of .sh file is,
#!/bin/bash
java -jar /xxx/yyy.war
In my log file, I mentioned the path as
./logs/xxx.log
when I run the ap in intellij, I could see the log files to be in the same folder as the project.
When I run the app from terminal using java -jar /xxx/yyy/war the log files are in the same location as the jar file.
But when I try to call the .sh file using jsch inside java, the app started running but the log files does not appear anywhere. Not sure whether they are created or the location where they are created. How to make it appear in the same location as the .sh file while using jsch in java to execute the .sh file, springboot, gradle?
I am using ubuntu, log4j2, intellij, java, and jsch.
Your log files are probably under the home directory for your user. Run a fresh jsck and type pwd - they might be there.
Really with log files however you should fully specify the path. Either via a fixed location, e.g. /opt/app/logs/xxx.log, or via a symlink from a fixed location, or via a system environment variable that you know is always going to be set, e.g. $LOGS_HOME/xxx.log
Relying on ./ is a really bad idea, since it completely depends on the execution context.

Difference between running jar file and exe?

If you have a small program, you can run jar file and it will work fine. But if you convert jar file into exe, you still need java to run your exe file, so what's the difference between them and why do some people convert jar to exe?
An EXE is, ostensibly, an executable program that launches the local java to execute the bundle classes.
As you may know, on your computer you can associate certain file extensions with local programs. For example, .doc files with your word processor.
Similarly, .jar files can be associated with Java, so that Java can execute them. The jar file is considered "stand alone" if it has all of the necessary classes bundled within it, and a proper manifest pointing to the startup class.
So, by associating .jar with Java, clicking on it in your environment will launch Java with the given jar file.
An EXE doesn't need that association. It find java on its own with it's own launcher.
The next step is that you can actually bundle the JRE in to an EXE, so you don't even need to have the user install Java as a pre-requisite. But that's a different process.
People commonly use Java executable wrappers for two reasons - 1. to simply deployment for environments without a JVM, and 2. To make sure the exact Java runtime used for developing the application gets used to run the JAR. However, the practice is not that much widespread.
Java archive or jar is an archive of compiled java byte code and resources which can be run on a java virtual machine. ".exe" is a windows extension for directly executable code mostly used by installers or programs that do not need to be installed. I think your "people" are talking about installers.
An Exe file is an executable file that can be executed in Microsoft OS environment.
Jar file is container of Java Class files, including other resources related to the project. Jar file can be executed only if Java run time environment.
The JavaTM Archive (JAR) file format enables you to bundle multiple files into a single archive file.
The .class files compiled from java files, can not be launched directly. That is why it is needed to be converted to exe before it can run in a windows environment.The usual way to start a java program by batch file is not a convenient way. So inorder to avoid this difficulty we need to convert jar files into exe file.
Also converting it to exe. enables the program to run by simple double click on the program, instead of having to compile it with an IDE or through the JVM.
All that the exe will do is to start a jvm with your app, something like this: "java -jar app.jar".

What is the file type for the final java application?

I finished a small program. What is the standard file type for the final application written with Java, so it can be run on any computer, easily and without any computer knowledge?
I've been told it's JAR, but Eclipse for example is an .exe file.
What's the standard file type for big, normal applications in Java?
Are most applications distributed in JAR, or rather in .exe or something else?
Serious desktop applications are packaged with platform-specific launchers, which are not written in Java. The launcher must first find out how to run the JVM installed on the system, and then pass it either the path to the executable JAR to run, or the complete classpath along with the name of the main class.
In other words, "it's complicated".
Most desktop applications are distributed using .jar files. A .exe is windows-specific, and non-portable across different operating systems. It's easy to find installers (or "launchers") that will simplify the distribution of a Java program in other platforms, but anyway you'll find that .jar files are the usual packaging mechanism.
If you have a small, simple Java program the easiest approach to distribute it would be to pack it in a .jar, making sure to make it executable. And remember, the computer where your code is expected to run must have installed some version of Java, be it JRE or JDK.
Desktop java applications are usually distributed as jar files.
JRE can launch a runnable jar file using -jar param.
You have one of several options:
1 - Create an executable jar file. By providing information in a manifest within the jar file users can simply execute the jar file by however system-dependent means exist for their OS.
2 - Write a batch file or shell script to invoke the JRE against your jar file (and specify command line parameters for, eg: the main class, the classpath, JVM options, etc.)
3 - Use a tool like jexepack or jsmooth to wrap your Java code within a native executable. I've only ever used these to create Windows binaries - there may be other options for other platforms but shell scripts are typically easier to work with here.

How to include win32com.dll into a jar file?

I am developing a Java application which has to be executed and installed without admin rights. My application needs the win32com.dll (Java Communication API) and the file javax.comm.properties.
Normally, I just copy the dll to C:\Java\jre1.6\bin and the config file to C:\Java\jre1.6\lib.
But I can't do all that in the target environment. Is there a way to solve this problem?
E.g. passing the location of these files to the java command in the command line, or including the files into the jar and load them from the source code?
Yes, you can just use something like this
java -Djava.library.path=/path/to/the/win32com.dll -cp /my/classpath/;/my/classpath2/ my.main.TheClass

Wrap the application to create sh file in Ubuntu Linux

I have created one java application which takes number of external jar files and also VM arguments passed to it.
I want to create .sh file for that application so that I cat run it on any linux system.
Please suggest me any tool to create .sh file in linux and which will also takes care about the arguments which has to be pass to application to run it.
I have use the tool named JarSplice but its not working as there is problem in loading libraries after creation of sh file .
So please suggest any tool for that.
If you're using maven to build your application there is a plugin called appassembler-maven-plugin that can create a .sh file for your application.
The groupId is org.codehaus.mojo.
You need to generate an executable jar, then you can simply run "java -jar main.jar" from there.
There are many questions on stackoverflow on how to create executable jars (you need ot set stuff in the MANIFEST.MF file in the jar file), for instance:
How do I create executable Java program?

Categories

Resources