I am writing a Batch to auto-install Modded Minecraft (included everything needed). Installing Java seemed simple enough but I can't figure out how to install it silently with something like wget.
Example:
wget {java download link}
/s java-installer.exe (basically run it silently)
then wait for it to install (which I also can't find a good way)
if exist "java.exe" (goto java-installed) else (goto java-install-failed)
then on to the rest of my code
(Any answers are appreciated)
I tried to install java from the installer file in the batch but it just opens the file. I don't really know where to go from there. The ideal process would silently installed it and output the info from the java installer to the same command prompt window and the batch file
Related
I have an application that I need to be a self-contained app, installable, on computers that may not have Java. I'm using javapackager command to create an EXE that can be sent out to the users, containing all the parts needed. The app, in a simple sense, reads in a file referenced by the first param, does transformations on it, and writes back out next to the source file a result. All of that works when running it as a JAR directly, and also when running it via the built EXE.
The problem is that when triggering the executable, it immediately returns execution to the command prompt, rather than waiting for the process to finish. I don't want to have to poll the output directory to check if the file exists and then give some arbitrary timeout on when to stop looking - I want the app to know that once the console command has completed, the processing is done. At that time I can do logic based on if I find the result file, and alert if it is not found or whatever other logic is right.
Is there a way to tell the javapackager command to set a wait until Java has died (good or bad) before returning control? Barring that, is there a code snippet/concept that would make the app hold off releasing control back to the terminal until the JVM has died?
I can confirm this behaviour for apps that I've packaged using javapackager included with Oracle JDK 8, 9 and 10 as well as with snapshots from OpenJDK 13. While the resulting binaries behave "as expected" under macOS and Linux, the Windows binary merely seems to spawn a new process and exits immediately.
Beginning with Java 9 jpackager invokes jlink internally, which has an option --strip-native-commands which basically removes binaries from the embedded JRE. With Java 8 you didn't have this option and executables such as java.exe are always removed. But my tests show that the JRE is otherwise complete and you should be able to simply include java.exe manually (better test this thoroughly!).
Therefore I propose the following workaround:
Create the application directory using javapackager -deploy -native image
Copy java.exe from your system-wide JRE installation to {OUTDIR}\runtime\bin (check if your license covers redistributing java.exe!)
Create a .bat file inside {OUTDIR} that calls runtime\bin\java.exe -jar ./app/yourapp.jar.
Now add {OUTDIR} to your .msi or innosetup installer or .zip file or whatever means of distribution you choose ;-)
You can then invoke the bat file instead of the exe. Since it is just a wrapper for java -jar it will wait until your program finished.
For running a java code (that includes a JXInput code for a Joystick use), I only run this .bat:
jre1.8.0_66\bin\java.exe -Djava.library.path=d:\HG -jar HG11.9.jar
But, that works if I has PREVIOUSLY installed the VC redistributable.
As some people are not software specialists, they don't know how to install this vc_redist_.exe from https://www.microsoft.com/en-US/download/details.aspx?id=48145. I mention "" because it depends on the system they have (vc_redist.x64.exe or vc_redist.x86.exe).
I am sure that this problematics consisting in facilitating procedure of installation of a game and, more generally, a product has been already solved. So, what is the good practice to manually avoid to install the vc_redist?
In other words, is it possible to include this vc_redist in the .jar? Then, only running a .bat (like above) allowing to run the game.
If not, is it possible to run a single .bat or something else that:
- unzip the .zip file of my game (this file includes the game and the vc_redist)
- then automatically install the vc_redist, depending on the system (32 or 64 bits) - by what means?
Thanks a lot for your response
If you already have bat file for install best way to do this will be to include install of vc_redist in this *.bat before install. From what I know it is not posiible to include this in the *.jar. Better will be to pack all files into zip (together with this *.bat script).
To install vcredist in bat silently you will have to add these commands:
#echo OFF
reg Query "HKLM\Hardware\Description\System\CentralProcessor\0" | find /i "x86" > NUL && set OS=32BIT || set OS=64BIT
if %OS%==32BIT runas /user:Administrator %~dp0\vcredist_x86.exe /q /norestart
if %OS%==64BIT runas /user:Administrator %~dp0\vcredist_x64.exe /q /norestart
#rest of your script
Checking if system is 32bit of 64bit is taken from here (batch file to check 64bit or 32bit OS)
%~dp0 resolves to the full path of the folder in which the batch script resides.
Edit:
As the runas might not be the best solution to problem of running this as administrator I will direct you to these posts to read about running with administrator privilages in bat
How to code a BAT file to always run as admin mode?
How can I auto-elevate my batch file, so that it requests from UAC administrator rights if required?
I downloaded the Carrot2 Document clustering server build 3.15.0 for Mac. The read me file says:
The DCS requires a Java Runtime Environment (JRE) version 1.7.0 or later. To
run the DCS, execute the 'dcs' script and point your browser at
http://localhost:8080 for further instructions.
Mac OS Sierra doesn't make it easy, but I got 1.8.0_112 installed.
The problem is that I don't know how to execute the 'dcs' script.
There are .cmd, .sh, .war, and .jar files. I wasn't sure which of those to work with. I thought .jar looked promising, so I followed some of this thread and tried this in a terminal window:
java -jar invoker.jar
I cd-ed to the correct directory, but it just says Provide main class, but I'm not sure what or where that is.
Can anybody provide instructions or a link to how to do this?
Use the dcs.sh (on Linux/Mac) and dcs.cmd (on Windows) to start the server. The scripts will set some extra options for the JVM and then start the DCS. In case of any problems, append the -v option to see diagnostic output.
I'm trying to automate the install of a Java 7 runtime on my Windows Server. I can make the install run silently, but the Ask toolbar seems to get installed as well. This enrages me even more than when it prompts during the desktop install.
How can I make it stop? And while I'm at it, is there a way to not prompt for third-party products when doing the regular updates on the desktop?
It's easy! After downloading the executable installer (for example, http://download.oracle.com/otn-pub/java/jdk/7/jre-7-windows-x64.exe), open a command line with administrative privileges, go to your downloads directory, and run the executable with /s SPONSORS=0
For example:
jre-7-windows-x64.exe /s SPONSORS=0
This will not only run a silent installation, but it will bypass any sponsor offers.
I am trying to run a simple JAVA program once per day on a Windows 7 machine.
My code runs fine inside NetBeans. If I do a clean and build it suggests this:
C:\Program Files\Java\jdk1.7.0/bin/java -jar "C:\Users\User1\Documents\NetBeansProjects\Facebook\dist\Facebook.jar"
This does not work from the DOS prompt of course because of the space between program and files so I do this:
C:\Program Files\Java\jdk1.7.0/bin/java -jar "C:\Users\User1\Documents\NetBeansProjects\Facebook\dist\Facebook.jar" -jar "C:\Users\User1\Documents\NetBeansProjects\Facebook\dist\Facebook.jar"
This works from the DOS prompt.
I now create a task in Windows Scheduler to run:
C:\Program Files\Java\jdk1.7.0/bin/java
with arguments:
-jar "C:\Users\User1\Documents\NetBeansProjects\Facebook\dist\Facebook.jar"
When I then run it, all I see is a DOS box flashing up for a second. I expect the code to take about 30 secs to run. The code should persist data to a database and no updates happen.
The code also uses java.util.logging so I should see log entries and I don't.
I strongly suspect that I am not running the JAVA command properly or that there's a bad classpath issue that it present when running via Scheduler that isn't there when running from the DOS prompt.
Help would be appreciated. If you've seen this before and can sort it that would be great. If you can tell me how to get a meaningful error trace from Scheduler than that would also be really helpful.
Thanks!
I Think that you could create a simple batch script that will launch your program in this way :
#echo off
REM Eventually change directory to the program directory
cd C:\Users\User1\Documents\NetBeansProjects\Facebook\dist\
REM run the program
"C:\Program Files\Java\jdk1.7.0\bin\java.exe" -jar "C:\Users\User1\Documents\NetBeansProjects\Facebook\dist\Facebook.jar"
Copy it into the notepad and save as java_script.cmd and then schedule this script instead of the program directly.
I solved it after changing all fonts' references to "SansSerif"
I was using Jasper Reports inside Java to create a PDF file. It was working fine when I double click the batch file or Scheduler with Windows Server 2003 but not working with the Scheduler of 2008.
I tried many different things nothing worked so I though Could it be that Windows Server 2008 is blocking the access?.
Now is working perfect. So, if you are having problems check the references to anything you are using.
The scheduler will run under a different user unless you specify what user to run as. If it isn't running as your user then it won't be able to write to your directories.
The real problem to the original question is a java installation issue on Microsoft systems. Java jre installs into Program Files\java. The executable (java.exe) is only installed in that java\bin directory. Running from the command line, the os looks in the proper location for the java.exe. Running from other MS tools (such as VBA Excel or in this case TaskScheduler), it does not!
You can see that TaskScheduler is looking in the wrong place by viewing the tasks history in the TaskScheduler tool. Double click on some of the history events and one will list the action and return code. The action will show that the TaskScheduler is trying to run
"C:\Windows\system32\java.EXE"
So, copy java.exe from the java\bin directory into the place where the scheduler is looking, and now it will work.
Or update your task and provide the full path to java.exe.
You can also update the environment system path to look for java in the java\bin directory, but that has to apply to all users and sometimes this is faulty as well.