Путь к java bat

How to write a batch file to set classpath and execute java programs

Some of my java programs need so many jar files to execute. For executing this, I may have to add all of those jar files in classpath variable of environment variables or else have to set classpath manually at command prompt each and every time when I open a new cmd prompt. I do not want to add all jar files at classpath variable in environment variables and also set manually each and every time when I open new cmd prompt. I would like to write a script in batch file to set classpath and there it self need to run java programs. So that, when ever I want to run my programs, I will just run batch file and run my programs one by one. I have written a batch file to set classpath. But, when I run this batch file, it automatically get closed. So, Am not able to utilize the classpath I set by batch file.Again I had to open new cmd prompt, set classpath and run my java programs. To achieve this with batch file, how could I proceed. Appreciate any help. Thank you.

3 Answers 3

There is no need for a batch file to specify the classpath for Java on command line as Jack wrote in his comment.

Take a look on the version 7 Java documentation pages:

There is -cp or better readable for humans -classpath which can be used on command line to define the classpath.

The paths to multiple classes can be specified by using a semi-colon as separator.

Читайте также:  Дата для cookie php

And double quotes around all paths must be used if one path contains a space character.

"%JAVA_HOME%\bin\java.exe" -classpath "C:\Java\My First Class;C:\Java\MySecondClass" MyJavaApp 

This approach is mainly useful on using a shortcut (*.lnk) to a Java application which needs different classses than what is usually used and defined in system wide environment variable CLASSPATH.

But for developing and testing Java applications in a console window with a different list of classes than defined system wide, it is better to have a batch file for example with name JavaDevEnv.bat with following code

@echo off title Java Development Environment cd /D "Path to\Preferred Working Directory\For\Java\Development" set "CLASSPATH=C:\Java\My First Class;C:\Java\MySecondClass" 

and create a shortcut on Windows desktop or in Windows start menu with the command line

%SystemRoot%\System32\cmd.exe /K "Path to\Batch File\JavaDevEnv.bat" 

defined in the properties of the shortcut file (*.lnk).

The working directory can be also defined with Start in in properties of the shortcut file instead of being set in batch file using change directory command.

And an appropriate Comment should be also written in properties of the shortcut file, for example same as used on command title which sets the title of the console window as hint for which purpose to use this shortcut.

A double click on this shortcut results in opening a new console window, executing the batch file which sets window title, working directory and environment variable CLASSPATH used by Java executed from within this console window and then remains open for user input.

Источник

Путь к java bat

Gray Pipe

Приносим извинения. Запрошенное содержимое было удалено. Вы будете автоматически перенаправлены через 1 секунду.

Этот форум закрыт. Благодарим вас за ваш вклад. Если вам нужна дополнительная информация о том, где еще можно найти помощь, вы можете посетить страницу ресурсов.

Читайте также:  Polynomial function in python

Лучший отвечающий

Вопрос

Здравствуйте, столкнулся с проблемой работы приложения, которая требует, что бы оно обращалось именно к 32 разрядной версии Java. Приложение запускается через файл startserver.bat. Нужно что бы именно данный батник обращался именно к 32 битной версии JAVA, так как с 64 битной версией не работает. Подскажите, пожалуйста, как это сделать. Если необходимо могу приложить сам bat файл, есть даже пример того, как должен выглядеть дополнительный код, но, к сожалению, не понимаю куда он должен добавляться, не владею синтаксисом. Самостоятельный поиск информации пока результатов не дал. PS с батниками имею дело в первый раз.

Ответы

Запускайте программу на JAVA таким образом: C:\Program Files (x86)\Java\jre7\bin\javaw.exe -jar <путь к программе>Путь к javaw.exe должен быть для нужной вам версии, например 32 битной. This posting is provided «AS IS» with no warranties, and confers no rights.

  • Предложено в качестве ответа Жук MVP 6 декабря 2014 г. 12:47
  • Помечено в качестве ответа Maksim Marinov Microsoft contingent staff, Moderator 9 декабря 2014 г. 14:59

Источник

Путь к java bat

Gray Pipe

Приносим извинения. Запрошенное содержимое было удалено. Вы будете автоматически перенаправлены через 1 секунду.

Этот форум закрыт. Благодарим вас за ваш вклад. Если вам нужна дополнительная информация о том, где еще можно найти помощь, вы можете посетить страницу ресурсов.

Лучший отвечающий

Вопрос

Здравствуйте, столкнулся с проблемой работы приложения, которая требует, что бы оно обращалось именно к 32 разрядной версии Java. Приложение запускается через файл startserver.bat. Нужно что бы именно данный батник обращался именно к 32 битной версии JAVA, так как с 64 битной версией не работает. Подскажите, пожалуйста, как это сделать. Если необходимо могу приложить сам bat файл, есть даже пример того, как должен выглядеть дополнительный код, но, к сожалению, не понимаю куда он должен добавляться, не владею синтаксисом. Самостоятельный поиск информации пока результатов не дал. PS с батниками имею дело в первый раз.

Читайте также:  Рамка вокруг таблицы

Ответы

Запускайте программу на JAVA таким образом: C:\Program Files (x86)\Java\jre7\bin\javaw.exe -jar <путь к программе>Путь к javaw.exe должен быть для нужной вам версии, например 32 битной. This posting is provided «AS IS» with no warranties, and confers no rights.

  • Предложено в качестве ответа Жук MVP 6 декабря 2014 г. 12:47
  • Помечено в качестве ответа Maksim Marinov Microsoft contingent staff, Moderator 9 декабря 2014 г. 14:59

Источник

How to run Java application by .bat file [duplicate]

Simply create a .bat file with the following lines in it:

@ECHO OFF set CLASSPATH=. set CLASSPATH=%CLASSPATH%;path/to/needed/jars/my.jar %JAVA_HOME%\bin\java -Xms128m -Xmx384m -Xnoclassgc ro.my.class.MyClass 

Sure, call the java executable.

Mine is C:\Program Files\Java\jre6\bin\java.exe , so to run it I would do

C:\Program Files\Java\jre6\bin\java.exe -jar myjarfile.jar

If You have jar file then create bat file with:

It’s the same way you run it from command line. Just put that «command line» into a «.bat» file.

So, if you use java -cp .;foo.jar Bar , put that into a .bat file as

@echo off java -cp .;foo.jar Bar 
@echo off echo You Are going to creata Java Class set /p Name=Enter your Class Name?: echo Your class Name is %Name% & pause echo To creat a Notepad pause notepad %Name%.java set path=%PATH%;C:\Program Files\Java\jdk1.6.0_14\bin pause javac echo Your java Path succsussfully set. javac %Name%.java pause echo Successfully Compiled java %Name% pause 

1)open a notpad 2)copy and past this code and save this file as ex: test.bat 3)Double Click tha batch file. 4)put your java codes into the notepad and save it as N.B.:- save this java file same folder that your batch file exists.

The javac command will compile the java program and the java command will run the program and pause will pause the result until you cross it.

Источник

Оцените статью