How do I execute .jar java program on Windows 7 command line?

耗尽温柔 提交于 2019-12-07 06:27:21

问题


I have been looking things up online and could not find a good answer so far. I want to execute the YUI compressor tool to obfuscate/minify my javascript file. I do have JRE installed.

It looks like the file association is fine as you can see here:

C:\directory\tempFiles>assoc .jar
    .jar=jarfile

I set up file association using ftype:

C:\directory\tempFiles>ftype jarfile
     jarfile="C:\Program Files (x86)\Java\jre6\bin\javaw.exe" -jar "%1" %*

The compressor tool is saved as a .jar file and is called "yuicompressor-2.4.6.jar"

When I try to run the .jar file, the cmd kept saying that the word 'java' is not recognized as an internal command... this is how I run it:

C:\directory\tempFiles\yuicompressor-2.4.6\build>java -jar yuicompressor-2.4.6.jar [options] [input file]

Any help would be appreciated thanks


回答1:


Add the JDK / JRE bin folder path to your PATH. See here.




回答2:


How to run jar files

Open Command Prompt.

Run one of the below given command.

C:\Program Files\Java\jdk1.7.0_21\bin>javaw.exe -jar D:\yourfile.jar

C:\Program Files\Java\jdk1.7.0_21\bin>java -jar D:\yourfile.jar

Easy.




回答3:


The environment variable PATH needs to include JAVA_HOME/bin. This is usually done automatically when installing a JDK with a windows installer package.

However, if you only install the JRE - which is actually all you need, you need to mage the changes to the PATH variable manually




回答4:


Java comes up with jar extractor... so you can just go in bin folder and paste the jar file there.

then go to command prompt.... go to to the bin directory then use the following command:

jar xf jar-file (name of your jar file)

Hope this helps....




回答5:


Step 1

Create a batch file (ie: script.bat) and place it inside of this folder:

C:\Users{user}\Downloads\yuicompressor-2.4.7\yuicompressor-2.4.7\build

Step 2

Then put all of the JavaScript files you want to combine and the output file name of the combined file inside of your script.bat file:

java -jar yuicompressor-2.4.7.jar droplinemenu.js effects.js jquery-1.4.4.min.js jquery-ui-1.8.10.custom.min.js --type js -o combined.js

Step 3

Run script.bat as Administrator




回答6:


My solution using a combination of the answers above, my goal was to start a .jar file which is named CombatLogReader.jar, along with the game Star Trek Online.exe via a command prompt. at first i was typeing in Start "" ""C:\Program Files (x86)\Steam\SteamApps\common\Star Trek Online\CombatLogReader\CombatLogReader.jar" but the file would not start, while researching why i could start the file manualy but not via cmd. my research got me here,

i modified my bat file to point to the java directory

This is how my bat file looks

@echo off
rem Star Trek Online
START "" "C:\Program Files (x86)\Steam\SteamApps\common\Star Trek Online\Star Trek Online.exe" 
rem CombatLogReader
CD "C:\Program Files (x86)\Java\jre7\bin"
javaw.exe -jar "C:\Program Files (x86)\Steam\SteamApps\common\Star Trek Online\CombatLogReader\CombatLogReader.jar"
exit

and it works, now every thing i need starts with just one icon the command prompt dose stay open untell combatlogreader is clsoed, but it dose not interupt the operation of any thing

Kudo's to everyone, who posted niplets of answers,




回答7:


I tried this and it worked, I simply copied my java file to the directory C:\Program Files (x86)\Java\jre7\bin since I had installed JDK 7 and since I am running a 64bit machine: Yours could be C:\Program Files\Java\jreX\bin depending on which X version of java you are running.

I then fired up the command prompt, ran as administrator and simply changed directory to C:\Program Files (x86)\Java\jre7\bin by typing at the command prompt:

cd C:\Program Files (x86)\Java\jre7\bin

This changes the directory to the above directory at the command prompt, I then ran: java -jar myjavaprogram.jar

Lo and behold my java executable file fired up. The error was because the system could not find the java.exe in the folder your coomand prompt is currently in so you need to change that to C:\Program Files (x86)\Java\jre7\bin depending on which version of java you have installed and which bit of machine you are running.



来源:https://stackoverflow.com/questions/6084984/how-do-i-execute-jar-java-program-on-windows-7-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!