How to include win32com.dll into a jar file? - java

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

Related

How To Run Jar Which Is On Web Server

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..

How to run executable jar in other systems?

I have scripted a selenium web driver program in java on eclipse IDE.
This program gets the data from a excel sheet placed on my systems desktop and all the jars are added in the build path from my desktop.
EXAMPLE:C:\Users\PEOPLE\Desktop\selenium-server-2.53.0\selenium-2.53.0\libs.
The entire program is exported into a runnable jar file and placed on the desktop.
The jar file is working fine as expected.
Now the question is how to make jar file run in other systems?
what are the pre requisites to make jar file run in other system?
I see two things mainly:
A Java JRE installed so that you can run java -jar yourJar.jar or java -classpath yourJar.jar your.package.name.MainClass
A way to configure the path for loading your Excel sheet (specially if the path is different on the other system). For instance, you could read this path in your Java program from a configuration text file app.config located in the same repository of your jar.
Hope it helps :)
Create the same path for the Excel file as is in your system (else you need to edit the Config file) along with the name of the file.Now, just install the latest JRE in the system and you should be good to go.

Specifying a javaagent within the jar file to be run

I'm developing an OpenJPA application (no webserver, regular java se app). In order to make OpenJPA work with my application, I need to set the openjpa-all-2.3.0.jar as a javaagent.
java -cp ... -javaagent:/full/path/to/openjpa-all-2.3.0.jar -jar app.jar
As I am packaging the openjpa.jar within the app.jar anyway, I am now wondering how it is possible to specify the javaagent, as a jar within my application jar file.
This didn't work
java -cp ".;.\app.jar" -javaagent:openjpa-all-2.3.0.jar pckg.Main
There's no way to do it.
The JVM does not look at the classpath to find the specified agent; it is expecting a file path, and you also cannot specify file paths inside jar files.
JDK-4648386 is the related feature request, and was closed Won't Fix after 18 years.
However, what you can do is write code to copy the agent jar from a classpath resource to a temporary file, and then attach it to the current running JVM. The ByteBuddy Agent library provides tooling to do this.

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?

How to run Java applications without using an IDE or the command prompt

This is more curiosity than a problem:
I was recently wondering if there was a way to run compiled Java applications without using the cmd or an IDE such as Eclipse. I use Eclipse, but it isn't very useful if you want to run the program independently. Can you save Java files in Windows Explorer so you can create a shortcut for them? If so, how? Is there some sort of special extension to the file? I've heard of .JAR files, but I'm not sure what they are. Can anyone tell me how to do it?
.JAR files are archives containing - amongst other things - your compiled classes and a manifest file. You may set the main entry point of your application in that manifest. See Setting an Application's Entry Point.
Normally if you double click a jar file in windows it will be opened by javaw.exe -jar <yourFile.jar>. javaw.exe will lookup the manifest and try start the main class defined there.
create the jar file for java application using following syntax jar -cvf .jar . then use javaw.exe -jar

Categories

Resources