Here is an output to a simple piece of code:
/Library/Java/JavaVirtualMachines/jdk-18.0.2.1.jdk/Contents/Home/bin/java -javaagent:/Applications/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar=60596:/Applications/IntelliJ IDEA CE.app/Contents/bin -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath /Users/IdeaProjects/StringFormatting/out/production/StringFormatting Main
Print a Bulleted List:• First Point• Sub Point
Process finished with exit code 0
How do I remove the javaagent, jar, encoding and classpath from the output console?
Related
I'm trying to understand this batch job file, there are two and the first is returning an exit code of 0:
set JAVA_HOME="C:\Program Files(x86)\Java\jre1.8.0_221\bin"
%JAVA_HOME%\java -Xms125M -Xmx512M -Djava.ext.dirs=lib org.pg.test.ListOutput > output.txt 2>exception.txt
And this second one is returning an exit code of 1:
set JAVA_HOME="C:\Program Files(x86)\Java\jre1.8.0_221\bin"
%JAVA_HOME%\java -Xms125M -Xmx512M -Djava.ext.dirs=lib org.pg.test.ListOutput 1 0 > output.txt 2>exception.txt
What does the 1 & 0 after the file name mean exactly? Why is this making it return an exit code 1?
Both files run normally, with a successful output in output.txt.
Trying to google the exact syntax this is in (batch files were not written by me) but maybe I'm searching for the wrong thing.
The documentation for the java command is found
here for JDK/JRE version 18 (a fairly recent version), and
here for JDK/JRE version 1.8 for Windows, which appears to be what you're using.
The 1 and the 0 after the class name are arguments that will be passed to the Java program when it runs. As for why this causes the program to exit with a particular exit code, that depends on what the program does. It's impossible to answer that without seeing the source code of the program.
I have a jar file which I'm triggering through batch file like this:
SET JAVA_EXE="C:\Program Files\Java\jdk1.8.0_161\jre\bin\java.exe"
%JAVA_EXE% -jar TimeStampVerification.jar"
These are some of the outputs I get from running it
After this output I want to save the highlighted output in variable to perform If operation. If this output displays, I need to trigger another jar file.
Till now, I tried using :
#echo off
for /F "tokens=*" %%o in ('java -jar TimeStampVerification.jar %1') do set output=%%o
echo %output%
pause
However, it is not showing output. Please help.
Try
....'java -jar TimeStampVerification.jar %1^|findstr /b /L /c:"Timestamp"' ....
which should select the line starting (/b) with the literal string (/L) specified.
Please clarify what the output shown actually was. Telling us it's not showing what you expect doesn't contribute to our knowledge of the issue - after all, if it showed what you expected, you wouldn't be asking. What, then, did it show?
Latex file: 0.tex content:
\documentclass{article}
\begin{document}
\begin{equation}
\frac{\partial p_{dyn}}{\partial n} = A
\end{equation}
\end{document}
Shell file: 0.sh content:
latex /u/b/basnet/Desktop/0.tex
dvipng /u/b/basnet/Desktop/0.dvi
Command in Terminal:
>chmod 755 /u/b/basnet/Desktop/0.sh
>/u/b/basnet/Desktop/0.sh
Output:
Image, Dvi and other files generated by latex. You can see in the blue window.
Problem:
This works only via terminal not by executing the command via Java program.
Java Program Code:
Runtime.getRuntime().exec("chmod 755 /u/b/basnet/Desktop/0.sh");
Runtime.getRuntime().exec("/u/b/basnet/Desktop/0.sh");
System.out.println("Script executed successfully");
Output:
run:
Script executed successfully
BUILD SUCCESSFUL (total time: 0 seconds)
The first line of the code i.e. making the file executable works fine as I cross-checked. But second line where the script file contains the latex command doesn't work when running via Java. I need to generate those files through my program.
I guess this has to do something with environment, I'm not too deep into all this OS stuff, but I think I have a solution which worked for your example on my pc:
You have to change the names of the programs to the full paths for the use in your shell-file, because the java runtime doesn't find them. For example:
/Library/TeX/texbin/latex /u/basnet/Desktop/0.tex
The only thing that goes wrong is, that the output files appear one folder above where the tex file is located, which means you have to change either the output destination or the line for the dvi execution.
If you don't find the path for the programs, open a bash and type
which latex
and
which diving
This was tested on OSX Mavericks through virtual box, and on Yosemite on a macbook.
I have a simple executable jar named "HelloWorld.jar".
I am trying to create a .app bundle for this java application. (Obviously, my actual program is more complex, but I have whittled it down to the barest problems).
CASE 1 - SIMPLE BUNDLE WITHOUT JAVA - WORKS COMPLETELY
Step 1 - Test at Console - Works
At the console I type
echo "Hello World (no java)" > /Users/josh/Desktop/test-output.txt
I view test-output.txt and see the expected output.
Step 2 - Test with Script - Works
I make a simple bash script named test:
#!/bin/bash
echo "Hello World (no java)" > /Users/josh/Desktop/test-output.txt
I chmod +x test and then type ./test, I view test-output.txt and see the expected output.
Step 3 - Create Rudimentary App Bundle - Works
mkdir -p test.app/Contents/MacOS
cp test test.app/Contents/MacOS
open test.app
I view test-output.txt and see the expected output.
CASE 2 - SIMPLE BUNDLE WITH JAVA - DOES NOT WORK
Setup
File HelloWorld.java:
public class HelloWorld {
public static void main ( String[] args ) {
System.out.println ( "Hello World" );
}
}
File myManifest
Main-Class: HelloWorld
Did the following at console:
javac HelloWorld.java
jar -cfm HelloWorld.jar myManifest HelloWorld.class
Step 1 - Test at Console - Works
At the console I type:
java -jar HelloWorld.jar > /Users/josh/Desktop/java-output.txt
I get the expected output: Hello World
Step 2 - Test with Script - Works
I make a simple bash script named "helloworld"
#!/bin/bash
java -jar HelloWorld.jar > /Users/josh/Desktop/java-output.txt
I chmod +x helloworld and then type ./helloworld, I get the expected output: Hello World
Step 3 (With Java) - Does not Work
mkdir -p helloworld.app/Contents/MacOS
cp helloworld helloworld.app/Contents/MacOS
cp HelloWorld.jar helloworld.app/Contents/MacOS
open helloworld.app
I get the following error:
LSOpenURLsWithRole() failed with error -10810 for the file /Users/josh/Desktop/helloworld/helloworld.app
/user/Josh/desktop/java-output.txt appears, but has no text inside.
As you can see, it appears that something is happening where running java inside an .app bundle is giving me that -10810 error.
Note: I also tried a variation of the first example, where I had the bash script launch /Applications/TextEdit.app, and that worked successfully. It makes me suspect the problem is with java specifically.
Does anyone have any idea what's causing this problem and how I can fix it?
I do not currently have an OS X machine handy to test this, but hints on the web from another question seem to imply that you need to set JAVA_HOME and possibly PATH in order to make java work inside the app bundle.
Specifically, at the top of your shell script, before attempting to run your program, put the following lines, with appropriate changes for your system.
export JAVA_HOME=/path/to/my/java/install
export PATH=$PATH:/path/to/directory/containing/java
More generally, to diagnose the root cause of the problem, change the existing line in your script to capture stderr and see if that gives you any useful output that might have otherwise been swallowed by the app's environment.
java -jar HelloWorld.jar > /Users/josh/Desktop/java-output.txt 2> /Users/josh/Desktop/java-error.txt
If you are able to capture the printed error, it may suffice to show you root cause.
How to start .jar application from command line and wrote errors ( exceptionsand warnings, all what is in Console in eclipse during execution ) in errors.text on Windows ?
it think you can do this by starting your jar with the following command:
java -jar myJarFile.jar 2>> errors.txt
the 2>> is used to redirect error messages (System.err)
if you want to redirect normal ouput too use 1> myfile.txt