How do you embed an .ini in a WinRun4j executable? - java

The documentation on the WinRun4j page mentions that embedding an .ini file into an executable is supported:
Supports embedding (inside the executable) the INI file. See Embedded Resources section below.
The problem is, I can't see how to do it.
The RCEDIT executable mentioned in the Embedded Resources Section does not seem to have an option to do this.
The /N option says it sets the .ini file, but that didn't seem to do anything when I ran:
RCEDIT /N myExecutable.exe myExecutable.ini
The /P option says it prints the embedded .ini file, but when I ran it after running RCEDIT executables with the /N flag, I got an error
.ini file not found
I'm sure I'm missing something here.
Can someone tell me what I am doing wrong?

Related

How to run Saxon from command line

Can anyone please post detailed, step-by-step instructions how to install Saxon (10 HE) and how to run a transformation from the command line in MacOS (10.13.6)?
I have installed Java on my computer.
I have downloaded the SaxonHE10-6J.zip file from SourceForge.
Based on the recommendation here I have placed the saxon-he-10.6.jar in the myUserName/Library/Java/Extensions folder.
I then opened the Terminal application and entered a command based on this answer:
java -jar saxon-he-10.6.jar -'/Users/myUserName/Documents/path/to/mystylesheet.xsl' -s:'/Users/myUserName/Documents/path/to/some.xml'
This results in:
Unable to access jarfile saxon-he-10.6.jar
All my attempts, including moving the .jar file to the /Library/Java/Extensions directory or including a full path to the .jar file within the command failed with the same error message.
Please note that I am not a Java developer and I do not intend to use this in an application. All I want is to be able to perform an occasional transformation.
I should also note that the locations of my XML and XSLT files may change from one case to another. I would like to be able to keep the .jar file in a constant location and supply the paths to the XML and XSLT files as required - IOW, I want to have a command template where I only need to change the 2 filepaths (and possibly add some options to the transformation).
What do I need to do?
Eventually I got it working. Although these are not exactly the detailed, step-by-step instructions I was hoping for, I will summarize here what I have learned so far. Hopefully this will save someone the hours of frustration I had to go through.
Make sure you have Java installed on your computer. If not, download
from Oracle and install.
Download Saxon from SourceForge. Unzip and place it anywhere on your
hard disk, except:
do not place it in /Library/Java/Extensions or in myUserName/Library/Java/Extensions;
do not place it within a folder whose name contains a / (see below for description).
To initiate a transformation, make your command:
java -jar 'path/to/saxon-he-10.6.jar' -xsl:'path/to/mystylesheet.xsl' -s:'path/to/some.xml'
Alternatively, you can use:
java -cp 'path/to/saxon-he-10.6.jar' net.sf.saxon.Transform -xsl:'path/to/mystylesheet.xsl' -s:'path/to/some.xml'
This form can be also used to run XQuery by changing
net.sf.saxon.Transform to net.sf.saxon.Query.
For adding more options and/or parameters to your command, see the
instructions given here:
https://www.saxonica.com/html/documentation10/using-xsl/commandline/
but do not follow the instructions at the top of the page regarding
the form of the basic command.
Corrections/additions are most welcome.
Description of the problem with folder name containing /:
Put all 3 files (saxon-he-10.6.jar, mystylesheet.xsl and
some.xml in a folder named XML/RSS in my Documents folder;
Ran the following command:
java -jar '/Users/myUserName/Documents/XML:RSS/saxon-he-10.6.jar' -xsl:'/Users/myUserName/Documents/XML:RSS/mystylesheet.xsl' -s:'/Users/myUserName/Documents/XML:RSS/some.xml'
Received the following error:
Error: Could not find or load main class net.sf.saxon.Transform Caused by: java.lang.ClassNotFoundException: net.sf.saxon.Transform
Moved only the .jar file to the parent folder and ran the following
command:
java -jar '/Users/myUserName/Documents/saxon-he-10.6.jar' -xsl:'/Users/myUserName/Documents/XML:RSS/mystylesheet.xsl' -s:'/Users/myUserName/Documents/XML:RSS/some.xml'
Result: successful transformation.
Moved the .jar file back, renamed the folder to XMLRSS and ran the
following command:
java -jar '/Users/myUserName/Documents/XMLRSS/saxon-he-10.6.jar' -xsl:'/Users/myUserName/Documents/XMLRSS/mystylesheet.xsl' -s:'/Users/myUserName/Documents/XMLRSS/some.xml'
Result: successful transformation.
I don't ever use it myself: however myUserName/Library/Java/Extensions is special as far as the classpath is concerned (you don't need to put JAR files in this directory on the classpath), but it's not special as far as the -jar option is concerned - that needs to be an absolute or relative filename in the normal way and has nothing to do with the classpath.
If you've chosen to put the JAR file in this magic location, then I would use the command java net.sf.saxon.Transform options to pick Saxon up from the classpath rather than identifying the -jar location directly.
There are good reasons for NOT putting Saxon in this magic location, however; one reason is it will affect applications that don't actually want to use Saxon (they might be written to use some other XSLT processor, and you might not actually be aware that they use XSLT at all, until they stop working).

My .exe file from launch4j does not work like my java file. Am I missing something?

As someone new to java and bundling programs with code, I was able to successfully get the proper output running a simple new HelloWorld java file. So I believe there are no issues with the java file in terms of compiling it to a class file or running it afterwards, and that I have all the files needed in the java kit to create an executable file. However, I am not sure if I am using launch4j properly to get the .exe, either with setting up the .jar or through the process from making a proper .xml file.
The code below shows what I get when I try to put everything into the .jar file, but I guess the output is an error because a new .jar file isn't produced unless I take out the "m" from the "cvfm" in the jar command. The code does show something about the manifest being added regardless when doing so, yet I still do not get a proper application. After getting the correct output without launch4j, I stopped recreating the .java and .class files and just focused on the .xml when recreating the .jar file achieved no difference. I have tried in launch4j leaving the environment variables blank in the JRE tab or just included the same path of the system variables that the java file worked with correctly in the command prompt, and I have also switched the check of GUI to console in the header tab. Research has also told me to look up a manifest.mf file, to which I don't think I have that precise file in the JDK, but may have found something similar in the kit (at least when looking in typical areas like the bin folder).
C:\JavaTest>jar cvfm HelloWorld.jar HelloWorld.class
java.io.IOException: invalid header field
at java.util.jar.Attributes.read(Attributes.java:406)
at java.util.jar.Manifest.read(Manifest.java:234)
at java.util.jar.Manifest.<init>(Manifest.java:81)
at java.util.jar.Manifest.<init>(Manifest.java:73)
at sun.tools.jar.Main.run(Main.java:176)
at sun.tools.jar.Main.main(Main.java:1288)
C:\JavaTest>jar cvf HelloWorld.jar HelloWorld.class
added manifest
adding: HelloWorld.class(in = 426) (out= 289)(deflated 32%)
I always get a warning about signing when testing the wrapper, but I don't think that has been an issue like an actual error. Due to the nature of the numerous combinations, it is hard to keep track of what caused the differences in issues, but it seems that now leaving the JRE tab blank except for having a min JRE version yields the error "no main manifest attribute" right from the wrapper test in launch4j. Having the very end of the system variable path included in the environment variable field does the same thing. Before trying to recreate the .jar, switching the header to console would create a .exe without errors, but either opening the application would either do nothing or put the same "no main manifest attribute" output in the command prompt. Now, I can't even use launch4j to test wrappers that have the header on console even when building them produces no errors (yet the same error happens when opening the .exe). I am just trying to get the .exe produced from launch4j to provide the same output in the command prompt that I get when typing "java HelloWorld" there.
If I am indeed creating the .jar properly and working with launch4j properly, did I just miss the unlisted step of needing some sort of manifest file to work with launch4j? If so, how would I make sure I got it properly? Would it be seen in a bin folder or completely separate from the JDK? Would I need to move it to my JavaTest folder where the java/class/jar/exe files are? Any help is truly appreciated.
The 'm' in jar cvfm stands for manifest, and implies that you will be providing a file as argument which is the manifest. The f stands for: You will specify the file name.
So, HelloWorld.jar is the argument to the f, and HelloWorld.class is the argument to the m. Your class file, obviously, isn't a valid manifest file, hence why the error occurs.
Generally, use a build tool to make jars, such as maven or gradle. You need a manifest in order to have a Main-Class attribute, and you need a Main-Class attribute to create a runnable jar, and you need a runnable jar to launch4j-ify it.
Make a file named MANIFEST.MF. Create it with a plain text editor. It should contain:
Main-Class: com.foo.thisIsAPackage.YourMainClass
and nothing else.
Then:
jar cvfm HelloWorld.jar MANIFEST.MF YourMainClass.class
note that I'm pretty sure you MUST have a package or this is not going to work.

Drag&Drop file to jar file (in Windows Explorer)

I have written a Java application, that analyzes some data from within a zip file.
I can pass the filename as command line argument to the application (java -jar myapp.jar fileToAnalyze.zip) and it does what it is supposed to do.
Unfortunately it is somehow complicated to call the application via command line. I would like to simply drag the ZIP file to the jar and let it start. I have absolutely no idea how to do this. Could you please give some hints?
Thanks in advance.
It seems that windows doesn't allow file drops on jar files. But short of finding a solution for that you could instantiate a JFrame when you run your jar file and make it listen for dropped zip files on that instead.
An example of that can be found here.
It still (10/2021) seems that Windows does not allow this.
What you can do:
create a batch file with the java call to your program. This will open a command line window along with your program and might seem ugly.
create a desktop link to your java.exe (or javaw.exe). In the properties of the link, add "-jar YourJarFile.jar" as command line arguments to the link target.
In both cases, Windows will send the dropped file to your program as command line arguments.

Error opening zip file or JAR manifest missing : C:\Program

I'm on step "Running project on the Server" from https://developers.google.com/appengine/docs/java/webtoolsplatform#dynamic_web_project and I ran into a problem:
Error occurred during initialization of VM
agent library failed to init: instrument
Error opening zip file or JAR manifest missing : C:\Program
Another person reported a similar problem here: Error opening zip file or JAR manifest missing : C:/Program. But the solution was for a different set of technologies. I'm using Eclipse, Web Tools Platform, and Google-App-Engine.
Most likely it's because my Java is installed in C:\Program Files, a directory which contains a space. But I'm not sure how to fix this. I’m not sure how to safely move the Java\jre7 directory to a directory without a space in it.
Jordan Fish from Google Cloud Platform Support helped me solve this problem. He said:
As far as the error message when you try to start the dev_appserver, I believe this is probably due to a vm argument in the run configuration for your project. Can you please go to the run configuration (with the project selected, go to the Run menu and select Run Configurations), click on the Arguments tab, and see what is listed in the VM arguments text box?
Here was my original VM arguments:
-javaagent:C:\Program Files\eclipse\plugins\com.google.appengine.eclipse.sdkbundle_1.9.4\appengine-java-sdk-1.9.4\lib\agent\appengine-agent.jar -Xmx512m -Dappengine.fullscan.seconds=5 -Ddatastore.default_high_rep_job_policy_unapplied_job_pct=50
Here is what I changed it to (added double quotes around the directory that's passed as the -javaagent: param):
-javaagent:"C:\Program Files\eclipse\plugins\com.google.appengine.eclipse.sdkbundle_1.9.4\appengine-java-sdk-1.9.4\lib\agent\appengine-agent.jar" -Xmx512m -Dappengine.fullscan.seconds=5 -Ddatastore.default_high_rep_job_policy_unapplied_job_pct=50
This fixed my problem, I was able to complete step "Running project on the Server" from https://developers.google.com/appengine/docs/java/webtoolsplatform#dynamic_web_project
You just have to add "" to your jar file behind -javaagent:
If you use IntelliJ the solution appears to be slightly different. You need to edit the Run Configuration the same way that the Eclipse users do, but add the "VM Options" using this format instead:
-javaagent:[/absolute/path/DMEnhancerJava-1.0.jar][classes=META-INF/]
Note the formatting with the brackets after the colon with no spaces for each parameter. If you miss that you'll get a runtime error message about JavaAgent expecting that input format.
Also, remember that if you use a build tool like Maven or Gradle and add this to your JAVA_ARGS variable (via something like MAVEN_OPTS) you'll need to wrap the whole thing in double quotes.
The second parameter appears to be necessary to tell DMEnhancer what to instrument (mine was relative to the top level of my classpath; because my compiled POJOs were in the META-INF directory).
Lastly, you may notice that you sometimes get an error talking about a class being implemented in two places in the classpath internal to the VM:
Class JavaLaunchHelper is implemented in both <Two full classspaths shown here> One of the two will be used. Which one is undefined.
This seems to happen because of a bug in the JVM and is fixed (on MacOS X) in 1.8u152 (at the time of writing, this is considered an Early Access Release available here). See this other answer for more information on this JVM bug.
Run your cmd as an Admin. When you try to startup your server and you are not starting it up as an admin you get this error.
Rebuild your project or try mvn clean install
Export jar with manifest file in eclipse as follows:
OR
Merge manifest file with created jar.
CMD: jar ufm /Users/inzamam/Desktop/inzaa.jar META-INF/MANIFEST.MF

'Java' is not recognized as an internal or external command and program running

This is probably the most frequent question you get in the world, and I apologize, but I have to ask anyway. I recently downloaded the newest version of java (1.7.0_45-b18), and I recently finished making a small program for a local community of mine in Eclipse. I'd like to share it with them so anyone can run it by clicking it, but opening the jar file just hasn't seemed to work for me.
I attempted opening it with command prompt by using
java -jar StatCalc.jar
but it always tells me
'java' is not recognized as an internal or external command, operable program or batch file.
I looked up many solutions for this, the most common being to change your Path. So I went to the environment variables, and changed the path to
C:\Program Files (x86)\Java\jre7\bin\java.exe
But it still gives me the same result. Only when the directory is exactly in java, and the jar file is in the java bin folder can I run the program. I wan't any person to be able to run this.
How do I get command prompt to work and allow this program to be run by both me and other people in this small community?
The path shouldn't contain the executable itself - just the directory containing java.exe. So you want this on your path:
C:\Program Files (x86)\Java\jre7\bin
Restart your console, check that the path is correct (just run path and look at the output) and all should be well.
Note that if you're going to be developing Java code, you should probably use the JDK path instead of the JRE path. For example, my path contains c:\Program Files\Java\jdk1.7.0_17\bin. (Yes, I need to update :)
I hope you do not have changed your PATH variable, only added (...);C:\Program Files (x86)\Java\jre7\bin\ (on UNIX systems, use a colon (:) as the separator instead) at the end. Otherwise, you will have many issues with all other Windows applications. Note that you must add the folder that contains java.exe, not the path to the executable itself.
Then, try to restart your Command-Line or even your Windows session.
Optional: You may set JAVA_HOME to specify JDK location. See this link.
Here you have a tutorial of oracle for setting the path
http://docs.oracle.com/javase/tutorial/essential/environment/paths.html
C:\Program Files (x86)\Java\jre7\bin --> This would be your PATH variable.

Categories

Resources