jar xf file.jar not working in windows 10 - java

Not working in Windows 10:
> jar xf file.jar
'jar' is not recognized as an internal or external command, operable program or batch file.

In a PowerShell, you should first:
$Env:Path+="C:\Program Files (x86)\Java\jre1.8.0_181\bin"
Change jre1.8.0_181 according to your installed Java Runtime Environment. For sanity check, you can print the updated path:
$Env:Path
Then:
java -jar -h
I still haven't figured how to get the xf subcommand to work though.

Set the JAVA_HOME in Environment variable.
Then set path.
then open a new Command prompt and type
$ javac -version
It should print something like that
javac 1.8.0_152
Now try

Related

Java - No Main Manifest Attribute, in App.jar error even though MANIFEST.MF file is in /META-INF

I have been trying to get this to work, but it won't. I went through the Archive Manager and found the MANIFEST.MF file in App.jar/META-INF/ so I don't know why it says there isn't one!
chmod-ing it with chmod +x ./App.jar and running ./App.jar returns
bash: ./App.jar: cannot execute binary file: Exec format error
Running Linux Mint 20 (Based on Ubuntu 20.04) With OpenJDK 11.
Use java -jar App.jar to run the executable JAR file.
There is a way to make JAR files directly executable using the binfmt_misc kernel feature but most users/linux distributions don't bother to set it up.

How do i fix this .bat file so it can run in macOS?

I have this .bat file created and working perfectly in Windows. When I tried to run this file from macOS terminal, it shows some error.
I've already had JRE installed in my Mac. I also added:
JAVA_HOME=/Library/Java/Home
export JAVA_HOME;
to my .profile file. All the jars needed are also in a folder beside the .bat file.
This is what's inside the .bat file:
shell
"%JAVA_HOME%\bin\java.exe" -cp .;libs/*;api-security-generator-0.0.1-SNAPSHOT.jar jatis.avantrade.security.securitygenerator.Main
I tried deleting the 'java.exe' from code above, but the error still showed up.
I expect to run this .bat file perfectly.
When it comes to setting JAVA_HOME (on macOS) it's better to use
export JAVA_HOME=$(/usr/libexec/java_home)
inside your ~/.profile. You can also pick any version you like by using -v option.
To list all JVM installations, call:
/usr/libexec/java_home -V
to select one of them, use
export JAVA_HOME=$(/usr/libexec/java_home -v version)
then, you can use it like this
$JAVA_HOME/bin/java -cp .:libs/*:api-security-generator-0.0.1-SNAPSHOT.jar jatis.avantrade.security.securitygenerator.Main
turning .BAT to .sh
you can also create a wrapper script like this
#!/bin/bash
export JAVA_HOME=$(/usr/libexec/java_home)
$JAVA_HOME/bin/java -cp .:libs/*:api-security-generator-0.0.1-SNAPSHOT.jar jatis.avantrade.security.securitygenerator.Main
Make sure to make it executable
chmod +x script.sh
Then, you can call it following way
./script.sh

Create a Run file in java

Is there a way to create a "Runfile" in java which runs the program just by using a command run, like Makefile and make?
I am using linux and have to type this command very often java -cp ../lib/*:../zookeeper-3.4.6.jar:. WordCount. It would be convenient if there was a easier way!
Make a shell script name run and place your required command.
Now make the run script executable -
chmod u+x run
Now you just execute the shell script from the terminal. If you need further improvement and if you are in ubuntu then you can create a bin directory at your home (~). Then you can place all of your commands in it. Generally your ~/.profile file contains information about the bin directory at your home. Now the bin directory works as your private bin. If your ~/.profile file doesn't contain any information about the bin directory then you can add the following line in your ~/.profile -
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi

Use Windows Batch File to start a Java program

I am not familiar with batch script, but I want to create a Windows Batch File to start a Java program. The problem is that it has to specific the path where JRE is installed. When you install both JRE7 and JRE8, the name of that JRE8 folder would call something like jre1.8.0_20 or jre1.8.0_40 with the version number in the back. When you have only JRE8 installed, the folder would call jre8. Is there an easier way to find where the most updated JRE installed and then execute it? Thanks.
start ..\..\Java\jre7\bin\javaw.exe -Xms512M -Xmx1024M -Djna.library.path=.\lib -cp example.jar; com.example.main
You should be able to get the location of javaw.exe by executing where java. This can be set as a variable inside a batch file like this:
# sets a variable called 'java' to the location of javaw.exe
for /f "delims=" %a in ('where javaw') do #set java=%a
# execute you jar file
%java% -jar <app.jar>
Noticed that the above only seems to work when running directly from the command line. Here is another example that should work in a batch file:
# run.bat
#echo off
setlocal enabledelayedexpansion
for /f %%a in ('where javaw') do (
set java=%%a
)
!java! -jar %1
The above batch file should be called with the name of the jar file:
run.bat app.jar
I think it's best to just user JAVA_HOME and/or JRE_HOME and let the user / sysadmin worry what's installed.

javac: invalid flag: activation-1.1.jar

I'm using Tomcat7 , jdk 1.7.0_55 & eclipse, when I trying to compile the entire project(Java Code) using COMMAND PROMPT, its showing Error Like
javac: invalid flag: D:\COMPILE\lib\activation-1.1.jar.
The given below steps are followed to compile the code.
Step.1: dir *.java /s /b > FilesList.txt
Step.2: javac #FilesList.txt -d compiledCode -cp D:\COMPILE\lib\*.jar
After run the Step.2 command its showing Error.so I removed the error jar file from my lib folder & run the command but its showing same error with another jar.
Note: I Already have ANT build.xml but I want to compile the project through COMMAND PROMPT.
The lib*.jar gets expanded by the command shell. You need to avoid that by using quotes.
***** -cp "D:\COMPILE\lib\*" *****
The argument to -cp is a single path list (like $PATH, not multiple arguments with one path each). Multiple files can be separated by : (or ; on Windows)

Categories