I have created a batch for my java swing application.After running batch the UI vanishes in seconds.
How to put my swing UI on hold until and unless we close it manually.
My batch file as below:
#echo on
set PATH=.;%PATH%
set CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
echo "Installing"
"%JAVA_HOME%\bin\java" -Xms512M -Xmx1G -classpath ./Installer/bin/plexus-classworlds-2.5.2.jar -Dclassworlds.conf=installer.conf %CLASSWORLDS_LAUNCHER%
pause
You can try the below and see:
Set the classpath to include the dependent jars if any and the location of the class files(bin folder)
set java home
execute the Main Class(with the main() method, com/main being the package name,change it according to your package structure)
Sample batch file:
#echo on
For /F "delims=" %%i in ('cd') Do set currentdir=%%i
SET CLASSPATH=%currentdir%\bin;%currentdir%\lib\poi-3.9.jar;
set JAVA_HOME=C:\Program Files\Java\jre6
SET path=%JAVA_HOME%\bin;%path%;
java com/main/MainRunner
pause
Check if this helps.
Related
Installing FireEye sets JAVA_TOOL_OPTIONS and when launching my application jar, following message is shown and jar is not launched:
Picked up JAVA_TOOL_OPTIONS:
-agentpath:"C:\Windows\FireEye\JavaAgentDll_00.dll" Cannot open project
Following SO post suggested to unset the JAVA_TOOL_OPTIONS variable but I don't want to change global settings. Is there an option to bypass this variable check(i.e. ignore JAVA_TOOL_OPTIONS) while launching my jar?
Use batch file like this.
#setlocal
#set JAVA_TOOL_OPTIONS=
java -jar your.jar
#endlocal
I have a Java jar file located in:
C:\Users\myusername\bin\MyDir\MyApp.jar
I also have some required properties files (needed as input arguments to the .jar file) located in the same directory as the .jar file.
I created a runme.bat file here:
C:\Users\myusername\Desktop\runme.bat
In the runme.bat file, this is what I have:
setlocal
set JAVA_HOME="C:\Program Files\Java\jdk1.8.0_161\bin\"
set PATH=C:\Users\myusername\bin\MyDir\
start %JAVA_HOME%javaw -jar %PATH%MyApp.jar %PATH%propertiesfile.properties
However, whenever I try to run the .bat file, I get the error:
Windows cannot find '-jar' Make sure you typed the name correctly, and then try again.
On the command line I see Windows trying to do this:
> "C:\Program Files\Java\jdk1.8.0_161\bin\"javaw -jar C:\Users\myusername\bin\MyDir\MyApp.jar ...
I get this error when running from the command line. If I simply double-click the .bat file, a cmd window comes up and quickly disappears.
So, what am I doing wrong?
Thanks!
Use Double quotes around the set command, not inside the variables.
Also, I see no reason to use the START command unless you want to do more in your batch file in the original command prompt after starting your Java in a second command prompt. Possible but seems unlikely.
Generally, you will just type in the executable or use CALL so that the executable runs and control returns to the batch after reaching conclusion.
Additionally, you changed your system path variable to be just the path of your java files which will make the session pretty screwy. Thankfully this should only persist in your open command windows and those spawned by the original window, so close them all and then use a different variable name for your path.
So I will put this both ways, using Call, and using start.
Here is your code using call:
#(
setlocal
ECHO ON
)
set "_Title=Runnning My Java"
set "JAVA_HOME=C:\Program Files\Java\jdk1.8.0_161\bin"
set "_MyJarPath=C:\Users\%UserName%\bin\MyDir"
TITLE "%_Title%"
CD /D "%JAVA_HOME%"
CALL "%JAVA_HOME%\javaw.exe" -jar "%_MyJarPath%\MyApp.jar" "%_MyJarPath%\propertiesfile.properties"
(
ENDLOCAL
EXIT /B 0
)
Here is your code using the start command:
#(
SETLOCAL
ECHO ON
)
set "_Title=Runnning My Java"
set "JAVA_HOME=C:\Program Files\Java\jdk1.8.0_161\bin"
set "_MyJarPath=C:\Users\%UserName%\bin\MyDir"
start "%_Title%" /D "%JAVA_HOME%" "%JAVA_HOME%\javaw.exe" -jar "%_MyJarPath%\MyApp.jar" "%_MyJarPath%propertiesfile.properties"
(
ENDLOCAL
EXIT /B 0
)
So I am new to using and creating batch files. I was wondering what is wrong with my file. I want to make it where it sets the path so I can compile my java file in cmd. Here is my code
#echo off
:start
rem set path="c:\Program Files\java\jdk.1.8.0_102";
set path=%path%;c:\Program Files\java\jdk.1.8.0_102
cls
pause
rem goto start
I am not to sure which one is right between the 2 paths so I was just testing.
setx JAVA_HOME "C:\Program Files\Java\jdk1.8.0"
setx PATH "%PATH%;%JAVA_HOME%\bin";
JAVA_HOME: stores location of the JDK’s installation directory.
PATH: stores paths of directories where the operating system will look, to launch the requested programs quickly.
Try this:
set path="C:\Program Files\Java\jdk.1.8.0_102\bin";%path%
Having read the post at .bat files, nonblocking run/launch,
I still cannot achieve what I need: to have the .BAT file close once the start command is executed. My problem is that when the JVM starts the application launches a window so I end up with 2 windows being opened, when in fact one of them (the .BAT command) is just a startup process and doesn't do anything meaningful to the user.
I paste the .BAT code here:
#echo off
setlocal
rem Starts the application
rem Check for Java Home and use that if available
if not "[%JAVA_HOME%]"=="[]" goto start_app
echo. JAVA_HOME not set. Application will not run!
goto end
:start_app
echo. Using java in %JAVA_HOME%
start "Application" "%JAVA_HOME%/bin/java.exe" -jar lib/pathToMyJarFile
goto end
:end
I'd like the .BAT process to terminate (or at least the window to close) once the JVM starts.
Try javaw.exe instead of java.exe.
Use start /b, see this:
http://zeroflag.wordpress.com/2007/05/12/start-command/
I have a java application launched by a .cmd file. I want to set the classpath of the application through this batch, all the needed jars are into a lib folder.
Here is what I tried :
set _classpath=.
for %%i in (%1/lib/*.*) do ( set _classpath=%_classpath%;%%i )
Surprisingly, it seems that it does not act as expected. Let's say there is 3 jar in the lib folder :
pikachu.jar
sonic.jar
mario.jar
Here is what happens :
set _classpath=.
set _classpath=.;pikachu.jar
set _classpath=.;sonic.jar
set _classpath=.;mario.jar
Obviously, what I am looking to get is
set
_classpath=.;pikachu.jar;sonic.jar;mario.jar
Any idea ?
Thanks and regards,
Place this at the top of your batch file:
setlocal enabledelayedexpansion
Then inside the for loop, replace %_classpath% with !_classpath!
Without delayed expansion enabled, %_classpath% gets expanded once, at the beginning of your for loop.
[Edit] In response to a comment, here is a full code-listing
#echo off
setlocal enabledelayedexpansion
set _classpath=.
for %%i in (%1/lib/*.*) do (
set _classpath=!_classpath!;%%i
)
echo %_classpath%
pause
CMD.EXE is expanding the %...% before running the loop.
You need delayed variable expansion, this is explained in set /? from a command prompt.