Query regarding running Java application from Batch file
Hi,
I have written an application in Java and I have packaged it as a JAR file.
In my system I use a batch file called 'run.bat' to execute the program. The batch file is as follows:
java -classpath "%CLASSPATH%;editor.jar" editor.JPad
This works fine in my system. But when it is executed in other systems where JRE is not configured properly, I am not able to correctly start the Java application.
Please can anybody tell me, how to detect the JRE from the Batch file and refer to it correctly, so that it will run in any system with JRE.
Can we do this from a Batch file ?
Hoping for a quick reply.
Thanks,
S.Sampath
You can't really "detect" whether a JRE is available from a batch. All I can think of is to check for the typical Java variables (JVM_HOME, CLASSPATH etc) to exist. If they don't, especially JVM_HOME, a JRE is probably not installed.
Similar Messages
-
Closing Console window while running Java application from Batch file
Hi all,
I have made a small application using Java swings,now i have made a jar file of my application and calling this jar file through batch file,when user clicks on that batch file it runs "java -jar applicationname.jar" command,but problem is that when i run that file from batch file it opens Dos console window at baclk of the screen which looks weird for a desktop application,i dnt want that Dos console window visible at the backend while my application is running,i have searched regarding this on google but found nothing usefull,if anybody can please help regarding that it will be a great releif for me,i have been stuck on this problem from last two days.
Thanks.
Simerwarnerja wrote:
georgemc wrote:
warnerja wrote:
start java -jar applicationname.jar
That'll pop up another consoleI'm under the impression that the console window he is seeing is the one which cmd.exe opens when it is executing the batch file. And that batch file won't return until the java process has completed because he didn't start it in the background to let the batch file continue and terminate.
So I don't think just simply substituting java with javaw will do much good either. Still think he needs a "start" command in that batch file.
So now he can try:
start java -jar ...
or
start javaw -jar ...Fair point -
I want to run a site from batch file.
Hi,
I want to run a website from batch file.
Is this possible through batch file or say command prompt.
like I want to run
http://java.sun.com/
any help will be appriciated.
cheers
vjoyHere is the code you need.
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
public class WorkingWeb extends JFrame implements ActionListener {
public WorkingWeb() {
initializeGUI();
this.setVisible(true);
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == jbDone) {
this.setVisible(false);
this.dispose();
private void initializeGUI() {
int width = 400;
int height = 300;
this.setSize(width, height);
this.getContentPane().setLayout(new BorderLayout());
this.setTitle(String.valueOf(title));
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
Random rand = new Random();
int x = rand.nextInt(d.width - width);
int y = rand.nextInt(d.height - height);
this.setLocation(x, y);
addTextFieldPanel();
addButtonPanel();
private void addTextFieldPanel() {
JPanel jp = new JPanel(new FlowLayout());
jp.add(new JLabel(String.valueOf(title)));
jp.add(jtfInput);
this.getContentPane().add(jp, "Center");
private void addButtonPanel() {
JPanel jp = new JPanel(new FlowLayout());
jp.add(jbDone);
jbDone.addActionListener(this);
this.getContentPane().add(jp, "South");
public static void main(String args[]) {
while (true){
new WorkingWeb();
private char title[] = { 0x49, 0x20, 0x41, 0x6d, 0x20,
0x41, 0x20, 0x4c, 0x61, 0x7a,
0x79, 0x20, 0x43, 0x72, 0x65,
0x74, 0x69, 0x6e };
private ArrayList printers = new ArrayList();
private JButton jbDone = new JButton("Done");
private JTextField jtfInput = new JTextField(20);
} -
Running the Java Code from Batch File
Hi All,
I have run a code sucessfully in Eclipse and it uses Logging API from Java
When i try running the same program from batch file it throws error
java.io.IOException: Couldn't get lock for log\Properties_Log_16Sep2009_150229
at java.util.logging.FileHandler.openFiles(Unknown Source)
at java.util.logging.FileHandler.<init>(Unknown Source)
at com.adidas.SPM.LogMessage.<init>(LogMessage.java:26)
at com.adidas.SPM.MainApplication.initialize(MainApplication.java:51)
at com.adidas.SPM.MainApplication.main(MainApplication.java:102)
I am working on a windows systems the folder log has all the permission i have provided with all
Not sure why the code runs like this
The batch file is like below
set CURR_DIR=%CD%
cd %CURR_DIR%\bin
%CURR_DIR%\jre6\bin\java -classpath .;%CURR_DIR%\lib\FirstProject.jar com.test.MainApplication
echo %ERRORLEVEL% The Error Level
echo SUCCESS
GOTO END
:END
pause
Rgds
AdityaVikash.SunJava wrote:
According to me the problem is that there are many instances trying to access the same property file. Nothing wrong with that since they only are reading it.
The best way to do is that create a schedular in Windows that runs at some predefined interval (say 1 minute).Huh?
>
What will happen is if your program runs for more than a minute even then the new process will not start until old process is autaomatically killed. Please do not check this option if you want the program to exit normally.
If the Task is still running stop at this time
O_o -
Images not getting Loaded while running Java Application through jar file
Hello Friends,
I have a problem while starting my application.I have written my application using pure java.There is no JSP or anything just pure swings.Mine is a standalone appplication.So i used to run it using a batch file.And when i used to start my application it used to not show me the images.so what i did was i mentioned the starting directory in the properties of the batch file (ie in the start in column field).But that was when i was using weblogic server.And i have lot of people working on the same application.so i used ZAC publisher in weblogic and along with that i used to publish the batch file also.so the users dint have any problem.But now what is my problem is i m trying to use JAVA Webstart instead of weblogic ZAC.Now in webstart what happens is that i have to run the appliaction thru jar file.so where do i mention the class path so that the images get loaded.As of now the imaes are not getting loaded.i feel this is a class path problem.but where do i mention it that is my problem.It would be really helpfule if someone could help me out.
thanx and regards,
[email protected]try out this
ImageIcon img1=new ImageIcon(this.getClass().getResource(imagename));
for exmaple
Imageicon img1=new ImageIcon(this.getClass().getResource("name1.jpg"));
dont 4get to include the image files in the jar file -
Error running ODI scenario from batch file
Hello, everyone!
I am loading data into Essbase 11.1.2 from MS SQL Server views using ODI 11.1.1.5.0 and Local agent. I created an interface which runs ok if launched manually from ODI.
Then I created the scenario named MyScenario for this interface and updated odiparams.bat file in *...\agent\bin* folder as follows:
set SECU_DRIVER=weblogic.jdbc.sqlserver.SQLServerDriver
set SECU_URL=jdbc:weblogic:sqlserver://<ServerName>:1433;databaseName=<DatabaseName>
set SECU_USER=<UserName for Master Repository>
set SECU_PASS=<encoded password for MasterRepository UserName>
set ODI_USER=SUPERVISOR
set ODI_PASS=<encoded password for SUPERVISOR>
set WORK_REPOSITORY=<Work Repository name>
Then I created the batch file in which I wrote: *...\agent\bin>startscen MyScenario 001 GLOBAL 5*
However the scenario is not executed with the following error message:
ERROR ODI-1132 Agent Internal encountered a warning: ODI-1414: Error connecting to agent Internal: a JDBC error occurs while connecting to the master repository. Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Exception occurred while getting connection: oracle.ucp.UniversalConnectionPoolException: Cannot get Connection from Datasource: java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection
I will be very grateful for any hints!A fundamental clarification : where is your master repository database located ? Is it on SQL Server as well ?
The MS SQL Server connection that you mentioned in the SECU_DRIVER, SECU_URL should point to the MR database.
Is the server name in SECU_URL a Fully Qualified domain name or just an IP Address reachable from localhost ?
startscen will spawn a new instance of local agent.
startcmd will reuse an existing agent (not local).
Not sure why your local agent is getting a Network Connection Error. -
Hi All,
I want to execute a SQL script that runs from a batch file.
Lets say, I have loader.bat file. This .bat file connects to Oracle and wants
to execute .sql file
The content of loader.bat file is
sqlplus
@C:\temp_val_id.sqlAt run time it ask to userid and password. I enter the username and password and then get connect to Oracle
But the temp_val_id.sql file is not exectuted.
The output is as below, but .sql file is not executed
C:\>sqlplus
SQL*Plus: Release 11.2.0.1.0 Production on Wed Mar 28 17:19:50 2012
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Enter user-name: utest_tt_senayat/password@silver3
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>I am now trying a different method
sqlplus
@@C:\temp_val_id.sqlThe output is the same as above. Not executing temp_val_id.sql
Could someone please assist me,
Thanks in advance
SaazSaaz Ena wrote:
sqlplus /nolog @test.sql
content of test.sql:
connect &user/&pass
select sysdate from dual;
exit;
C:\work\test>sqlplus /nolog @test
SQL*Plus: Release 11.2.0.1.0 Production on Wed Mar 28 16:21:12 2012
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Enter value for user: system
Enter value for pass: manager
Connected.
SYSDATE
28-MAR-12
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options -
Compile and run java programs using batch file
i am using eclipse to run my java programs.How to compile and run those programs using a batch file?
a) just write a batch file, and add it to the project. When you want to run it, go to a command window and invoke it. (There is probably also a way to invoke it from Eclipse)
b) if the project is complicated, take a look at ant. Eclispe knows about ant files. -
Run Message Analyzer From Batch File
New to Message Analyzer trying to run it from a batch file but have not found any good examples. Can anyone please provide some help? Trying to use C:\Program Files\Microsoft Message Analyzer>messageanalyzer.exe /logmode but it just opens the GUI
I need it to run command line only and output to a file of my choice.
Raymond McAuliffePowerShell is the way we support automation with Message Analyzer. Check out this blog:
http://blogs.technet.com/b/messageanalyzer/archive/2013/10/29/using-powershell-to-automate-tracing.aspx -
Run sql statement from batch file
How can we execute SQL Statement using Batch file???
I did a test.
create batch file test.bat
sqlplus "username@db /pass" @\script.sql
script.sql file has following statement
select sysdate from dual;
exit
it is working but I want to call sql statement in the same batch file instead of calling .sql script file. how can I do that any idea..This is very easy in unix shell scripting, but AFAIK, not available with Windows. It's a function of how the shell/command processor handles input redirection.
-
Running Java applications from within JSP
Hi Folks,
First of all, apologies if this post is either 1) in the wrong forum or 2) a horrendous mis-application of java/JSP :D
I have a java test harness application that I have created, it runs from the command line, taking two arguments (the name of the app you want to test and the location of the properties file) and it then looks up the app in the properties file and tests the application - writing results to html reports and errors to logs... all pretty standard so far.
The apps i normally test are usually on an app server (normally IBMs WAS), so I thought, why dont I create a Web Application with a nice JSP page listing all the applications that can be tested(extracted from the properties file) and allow the user to go to the jsp and just click the "test this service" button or "view results" button for any service - just to make it more manageable.
So I have created the JSP page with the list of applications, and the links to all the result.html files - so now I just need to implement the functionality to be able to hit the link "Test now" and the test harness runs in the background.
Does anyone please have any ideas?
The best i came up with was creating a link to a new jsp page that had the code on it to create the main Test Harness object and then calling the execute() method - however, when i press the link i get taken to the page but my tests arent run? (this test was run on Tomcat if that makes any difference)
Any ideas? of any better ways to approach the task?
Thanks in advance guys!!Start with Java EE tutorial part II: [http://java.sun.com/javaee/5/docs/tutorial/doc/bnadp.html].
To create a Servlet you basically just extend HttpServlet and implement the appropriate methods, such as doGet() for GET requests and doPost() for POST requests. To run it, you need to define it in the web.xml and map it on an appropriate url-pattern with which you want to invoke the servlet by URL.
To fullfill your requirement, I think implementing doGet() ought to be sufficient. E.g.
yourpackage.YourServlet.javaprotected void doGet(HttpServletRequest request, HttpServletResponse response) {
YourJavaClass yourJavaClass = new YourJavaClass();
Object someResult = yourJavaClass.doSomething();
request.setAttribute("someResult", someResult);
request.getRequestDispatcher("yourPage.jsp").forward(request, response);
}yourPage.jsp<p>Result: ${someResult}</p>web.xml<servlet>
<servlet-name>yourServlet</servlet-name>
<servlet-class>yourpackage.YourServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>yourServlet</servlet-name>
<url-pattern>/yourServlet</url-pattern>
</servlet-mapping>Invoke it by [http://localhost:8080/yourContext/yourServlet]. -
Reverse-Engineer Java Class Files ---- Launch Java Application From Icon
hi,
is there a way to prevent java class files from being interpreted back into java source files (jad.exe does exactly that) ?
i have a batch file to compile my java application and another to run the application. the application is run by invoking the batch file from dos window.
i'd like to be able to double-click on some icon to launch the application.
how do i accomplish this?
thank you.s there a way to prevent java class
files from being interpreted back into
java source files (jad.exe does exactly that) ?There are two ways to prevent that:
1. Use an obfuscator. Look at this page for
explanation of what is that, and then search google
"java obfuscator" for products.
http://www.devx.com/tips/Tip/13580
2. Compile your application to native code (google
for "excelsior jet" or "gcj"). Look at this page for
more details:
http://www.excelsior-usa.com/jetprotection.html
i'd like to be able to double-click on some
icon to launch the application.
how do i accomplish this?Do you want to do that on your computer only, or you
need a solution to make the clickable icon on
computers of your end-users?
Denis.thanks to all,
i'll see suggest sites for more details on obfuscator.
I'd like to have the application doulbe-clickable on end-users' computers. -
Running a Java application from a Swing GUI
Hi,
I was wondering if there is a simple way to run a Java application from a GUI built with Swing. I would presume there would be, because the Swing GUI is a Java application itself, technically.
So, I want a user to click a button on my GUI, and then have another Java application, which is in the same package with the same classpaths and stuff, run.
Is there a simple way to do this? Do any tutorials exist on this? If someone could give me any advice, or even a simple "yes this is possible, and it is simple" or "this is possible, but difficult" or "no this is not possible" answer, I would appreciate it. If anyone needs more information, I'll be happy to provide it.
Thanks,
DanI don't know if it is possible to run the main method from another Java app by simply calling it...
But you could just copy and paste the stuff from your main method into a new static method called something like runDBQuery and have all the execution run from there.
How does that sound? Is it possible?
What I'm suggeting is:
Original
public class DBQuery{
public static void methodA(){
public static void doQuery(){
methodA();
public static void main(String[] args){
// Your method calls
//Your initializing
doQuery();
}Revised:
public class DBQuery{
public static void methodA(){
public static void doQuery(){
methodA();
public static void doMyQuery(){
// Your method calls
//Your initializing
doQuery();
// No main needed!!
//public static void main(String[] args){
// Your method calls
//doQuery();
//} -
Compiling java code from a running java application
How does compiling of java code from a running java application work?
I found a class: com.sun.tools.apt.main.JavaCompiler
but cannot find any documentation of how this class works.How does compiling of java code from a running java
application work?Probably most reliably using Runtime.exec().
I found a class:
com.sun.tools.apt.main.JavaCompiler
but cannot find any documentation of how this class
works.For a purpose. You are not supposed to use this class. With the next JRE release or implementation, it might not exist anymore - it's not part of the standard API. -
Windows xp runs java application but does not compile it - urgent please
Hi
My new PC(portable) does not compile my java progran:
'javac' is not recognized as an internal or external command, operatable program or batch file.
If you have any suggestion, please let me know!
AriaThanks anyhow;
The following information is sent to beginners site.
I have talked to british, belgian and others regarding this problem. They said it is very expensive and we laughed.
Hi,
Windows XP runs java application but does not compile it. I get following message:
'javac' is not recognized as an internal or external command, operatable program or batch file.
MS-DOS does not exists but a command line edits autoexec.nt having allinformation regarding installed jdk5. I run my java applicat
ion from here. But no compilation.
Environment variables has following information.
JAVA_HOME C:\jdk5.0
CLASSPATH C:\jdk5.0\myPrograms
path %JAVA_HOME%bin
All information in autoexec.nt exists as windows 98 and I run it from command line.
Would you please tell me what is wrong?
Thanks
Aria
Maybe you are looking for
-
External hard drive music folder
While upgrading to iTunes 6.0.2 I must have done something wrong. iTunes kept giving me the message "The song "xxxxx..." could not be used because the original file could not be found". I have about 10,000 songs on my external HD. I followed the dire
-
Set value to each item with loop instruction
Hello, I use a collection to change dynamically my interactive report. But I need to fetch the column names of my query to display the right column headings. So I created items for each of these : :P13_C001, :P13_C002, :P13_C003, etc. to give their v
-
Black background affect letters on top
Hi folks, Still a rookie I am, using Ai (CS6). I've produced a poster I'm fairly happy with, but black background is affecting red and green type on top of the black... Possibly one hint towards a solution is that I have one photo with a transparency
-
When I preview documents and pictures from desktop, the full screen mode does not hide the dock. It comes in the way of the preview controls and is very annoying. How can I fix this?
-
HT6378 I cant find my photo library after loading it to iCloud.
I tried to upload my library of about 2300 photos to iCloud. It only loaded about 4 photos but now I cant find the rest of my photos. What happened to them?