简体   繁体   English

如何在Windows 7命令行上执行.jar java程序?

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

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. 我想执行YUI压缩器工具来混淆/缩小我的javascript文件。 I do have JRE installed. 我确实安装了JRE。

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: 我使用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" 压缩器工具保存为.jar文件,称为“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: 当我尝试运行.jar文件时,cmd一直说“java”这个词不被识别为内部命令......这就是我运行它的方式:

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

Any help would be appreciated thanks 任何帮助将不胜感激

Add the JDK / JRE bin folder path to your PATH. 将JDK / JRE bin文件夹路径添加到PATH。 See here . 看到这里

How to run jar files 如何运行jar文件

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. 简单。

The environment variable PATH needs to include JAVA_HOME/bin. 环境变量PATH需要包含JAVA_HOME / bin。 This is usually done automatically when installing a JDK with a windows installer package. 这通常在使用Windows安装程序包安装JDK时自动完成。

However, if you only install the JRE - which is actually all you need, you need to mage the changes to the PATH variable manually 但是,如果您只安装JRE - 这实际上就是您所需要的,则需要手动更改PATH变量

Java comes up with jar extractor... so you can just go in bin folder and paste the jar file there. Java提出了jar提取器...所以你可以进入bin文件夹并将jar文件粘贴到那里。

then go to command prompt.... go to to the bin directory then use the following command: 然后转到命令提示符....转到bin目录然后使用以下命令:

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

Hope this helps.... 希望这可以帮助....

Step 1 步骤1

Create a batch file (ie: script.bat) and place it inside of this folder: 创建批处理文件(即:script.bat)并将其放在此文件夹中:

C:\\Users{user}\\Downloads\\yuicompressor-2.4.7\\yuicompressor-2.4.7\\build C:\\用户{用户} \\下载\\的YUICompressor-2.4.7 \\的YUICompressor-2.4.7 \\构建

Step 2 第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: 然后将您要组合的所有JavaScript文件和组合文件的输出文件名放在script.bat文件中:

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 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 第3步

Run script.bat as Administrator 以管理员身份运行script.bat

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. 我的解决方案结合上面的答案,我的目标是通过命令提示符启动名为CombatLogReader.jar的.jar文件以及游戏Star Trek Online.exe。 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, 起初我输入开始“”“”C:\\ Program Files(x86)\\ Steam \\ SteamApps \\ common \\ Star Trek Online \\ CombatLogReader \\ CombatLogReader.jar“但该文件无法启动,同时研究为什么我可以启动文件manualy但不通过cmd。我的研究让我在这里,

i modified my bat file to point to the java directory 我修改了我的bat文件以指向java目录

This is how my bat file looks 这就是我的bat文件的样子

@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 并且它的工作原理,现在我需要的每一件事都只用一个图标开始,命令提示剂量保持打开,untell combatlogreader被打开,但它不会中断任何事物的操作

Kudo's to everyone, who posted niplets of answers, Kudo给每个人发布了一些答案,

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. 我尝试了这个并且它工作了,我只是将我的java文件复制到目录C:\\ Program Files(x86)\\ Java \\ jre7 \\ bin,因为我安装了JDK 7,因为我运行的是64位机器:你的可能是C: \\ Program Files \\ Java \\ jreX \\ bin取决于您运行的是哪个X版本的java。

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: 然后我启动了命令提示符,以管理员身份运行,只需通过在命令提示符下键入将目录更改为C:\\ Program Files(x86)\\ Java \\ jre7 \\ bin:

cd C:\\Program Files (x86)\\Java\\jre7\\bin 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 这会在命令提示符下将目录更改为上面的目录,然后运行:java -jar myjavaprogram.jar

Lo and behold my java executable file fired up. 看,我的java可执行文件被激活了。 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. 该错误是因为系统无法在您的coomand提示符当前所在的文件夹中找到java.exe,因此您需要将其更改为C:\\ Program Files(x86)\\ Java \\ jre7 \\ bin,具体取决于您的java版本安装了你正在运行的机器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 "如何在 Windows 上从命令行运行 Java 程序?" - How do I run a Java program from the command line on Windows? 无法使用Java程序执行jar文件。 我需要将文件路径作为命令行参数传递给jar文件 - unable to execute the jar file using java program. i need to pass the file path as a command line argument to the jar file 如何在由命令行执行的Java程序中包含JAR文件(Windows) - How to include JAR file in a java program that is being executed by command line (Windows) 如何在 Windows 上使用命令行执行具有外部依赖项的 jar 文件? - How to execute jar file with a external dependency using command line on Windows? 如何使用以下命令行在类 UNIX 中执行 jar 文件:java -jar mysolution.jar &lt; inputfile.txt - How can I execute jar file in UNIX-like using this command line: java -jar mysolution.jar < inputfile.txt Java执行命令行程序 - Java execute command line program 如何通过命令行使用硒罐运行Java程序 - How to run a java program with selenium jar through command line 从命令行在jar中执行Java按钮 - execute java button in a jar from command line 在命令行中用 external.jar 编译 java 程序 - Compile java program in command line with external .jar 从命令行运行 Java 程序/Jar - Running Java program/Jar from command line
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM