Can't run dynamically generated batch file from Java - java

In java I have dynamically created a batch file under program files in tomcat's bin directory and execute it dynamically, but it does not execute. If I double click the generated batch file it does execute. (Problem occurs on windows server machine.)
On my machine and many XP machine this process works fine.
So is it OS dependent, or the file is at program files so can't have permissions to execute or there is any other problem?

A proper answer requires you to supply more information; maybe by answering these questions, you will determine your answer.
1) Be specific about the Windows Server version (2003, 2008, etc.)
2) I assume Tomcat is running as a Service; what user account does it run as, and does this user account have appropriate permissions?
3) Post the code you have that creates the file. Post the code you have that is executing the file. Are you trying to execute the file after it is created, but before the output stream is closed?
4) Have you tried creating this file in a different directory than the bin folder of Tomcat?

Related

JAVA Properties file in Windows Virtual Store causing problems through updates [duplicate]

I try to make a setup with Inno Setup for my program.
I have installed more file XML in the same folder as the .exe. The install work well, but when I run the program and modify the XML, the file is saved in another place, not the folder of the .exe and I can't find it. I think the file is stored in the PC because the program can open it without problems.
I also try to make the same setup with InstallAware Express 7 and it works well. Io I think it's not a problem in my exe but in Inno Setup.
Thanks
I think you are a victim of Windows File virtualization.
You probably install data files to Program Files folder.
That folder is not writable (unless your program runs with elevated privileges). If your program does not have application manifest, Windows considers it a legacy application that is not aware of its inability to write to Program Files and enables file virtualization. So, when your application tries to write the data/XML files, Windows redirects the write (and future reads) to a virtual store (C:\Users\username\AppData\Local\VirtualStore). The actual files in the Program Files are not modified.
It's difficult to answer, why it works with the InstallAware Express. If you tried it after the Inno Setup, the results can be affected by an existence of the file in the virtual store.
Anyway, the root cause is that your application tries to write the files in the Program Files. That's just wrong. No application should write to Program Files.
See also Application does not work when installed with Inno Setup.

How to create a file in Windows 8 system directories

I am running Windows 8.1, Netbeans and Java 7. I have a jar file sitting in the dist directory, on the "C:" drive. (Netbeans automatically creates a "dist" directory to store the jar files it deploys.) When I run the jar and specify the "dist" as a target directory, my program is able to create files in "dist" using "createNewFile". (My program can also read from and write to the new created files).
My problem is that my program does not seem to be able to create files elsewhere on
the C: drive, under Windows 8.1 (It is able to do so under Windows XP.) To be more specific, createNewFile does not create a file, does not throw an exception, and a System.out.println ("Message") statement placed directly after the createNewFile statement does not execute. No errors are reported anywhere. I have tried to deactivate User Account Controls but no avail.
Does anyone know directories in Windows 8.1, outside of "dist", to which my program could
successively write files and this without having to call upon administrative privileges? Thank you.

Java store config and other files

Currently i am storing a few config files and a history.xml file right next to my executable .exe.
However some users have reported that they have to run my program with Administrator rights, otherwise settings and history is not saved to these files.
Where should i save my config files and history.xml in order to not require my users to run the app with administrator rights?
Would be really nice with a solution that works on both Windows and OSX
Any ideas?
Your users are probably saving the files in a folder under Program Files or another 'protected' folder.
Either they should save it in a users-folder, or you should work with a full path to some path on the system, like 'C:/myapp/'.
You can use a helper function to check if you're using Windows or *Nix, and then depending on that return a certain path. I'm not close to my computer so can't test but this should work:
return System.getProperty("os.name").egualsIgnoreCase("Windows");
You can also make use of "user.home" for the users home directory (always writeable) and "file.separator" so you don't even need to check whether you're on Windows or not.

How to run a JNLP file with SQLite DB?

I'm new to JavaFX. I have a JavaFX Application which is generating a jar and a JNLP file. As a DB I'm using SQLite db. The system runs fine when running it on Netbeans IDE but does not get going with built files (jnlp, jar). Problem is the JNLP is unable to find the db location when running with JNLP.
How can I fix it?
How is the DB installed?
Presuming the installer can accept an 'installation path', I would tend to:
Use an installer-desc element to start Java code.
That pops a JFileChooser to allow the user to create/select an installation directory
That it then passes (that path) to the DB installer, and..
Persists the path using the PersistenceService
When the main GUI starts, it can:
Read the DB path from the PersistenceService
Invoke/start the DB.
For demos. of some of the parts of that, see:
The PersistenceService.
The installer-desc that invokes the ExtensionInstallerService.
Sign your application to give it the permissions it needs to run correctly in jnlp mode.
If you have permissions on the machine you're running on and the user accepted them you should be able to write a new database file to the local system.
Make sure that you check that the database exists and if not create it. Failing that, what is the exception?

How to run database program outside the Netbeans IDE?

I am really new to database and this is my first program in database using java Netbeans 7.1 --- It is summer on our country now and I am a student with the course I.T. Our next subject on programming is about database and since there's no class I spend my time learning database for preparation for the next school semester and I refer to this site as my guide for the first database program I currently making now.
http://www.homeandlearn.co.uk/java/databases_and_java_forms.html
I did everything in the tutorial and I actually done doing the program.
The final thing I did is I clean and build the program since I want the program to run with out opening the netbeans again I downloaded the JRE and make my database_form.jar as a jar executable. "database_form" the name of my Netbeans Project. I do that by making javaw in JRE.7 as my dafault when opening any jar files.
Anyway, this is how i run the program.
Running Program in Netbeans IDE
Using Netbeans, before my program works I first need to "Start Server" on JavaDB. because if I didn't do that an Exception occurred "Err. connecting to server localhost 1527 and so on"
Running Program using jar executable alone.
The Problem is there's an Exception and Err in connecting still occurred.
What I want to achieve?
I want the program to run without opening the Netbeans IDE and going to Java DB to click the "Start Server", I dont want to do that anymore. Or my second option is to start the server using command prompt so that I just have to make a bat file so that whenever I open my program database_form.jar I just place the bat file on my desktop and run it.
Second Problem!
Actually, I already try my second option by using command prompt to start the server but I forgot how I did it, I just found it on some website the only thing I remember is the Exception says "Failed to lunch the server because the database Employees is missing. Employees is the name of my created database.
The O.S. I am using is Windows 7.
Thank you for all the reply and sorry for the long text I just want to be specific, :D
Right, from your description there seems to be a couple of things you are confusing.
First, databases are typically run as servers with multiple clients connecting to them thus allowing they contain to be shared. When you start Java DB you are starting the Java DB database server.
That said, lightweight databases, such as Java DB can be run in an embedded mode as explained here. Remember that the directory you point to with the derby.system.home property will need to contain the database files, if not you'll need to create that programatically too.
Second, there's various ways to run a Java application outside of an IDE, but jars themselves are not executable in the same way an exe file is in Windows.
The simplest way is to call the java executable passing the necessary classpath and the name of the class containing the main method. For example if I had a class called com.example.Application that had been compiled to a directory C:\dev\example\classes the following command line would run the application:
java -cp C:\dev\example\classes com.example.Application
If there were dependencies on external libraries, as there will be in your case on the Derby JDBC driver, then those would also need including in the classpath resulting in something like:
java -cp C:\dev\example\classes;C:\dev\lib\derby.jar com.example.Application
There's a full set of document on the Java launcher here.
Now, back to the jar. Like I said, jars are not executable but there is something that's know as an 'executable jar'. This is the same as any jar except there are some special additions to the manifest to specify the application entry point or main-class and the class-path as described here.
Once the main-class and class-path are specified in the jar's manifest, the following command line would run the application:
java -jar C:\dev\example.jar
You can even associate the jar extension with the java exe and double clicking the jar will cause the application to launch (though on a dev machine it's probably more useful that the jar extension be associated with WinZip or simlar in order to open that jar).
The default database in Netbeans is Derby/JavaDB. So you need to:
add the jar of javadb/derby in our classpath (it maybe already present, as it is bundled with java when you install it in Ubuntu)
setup a path with the jdbc URI to save the database data
I personally recommend the usage of hsqldb or H2 for this: they support in-memory database, very useful for stand alone project with no persistence data or for tests.
If you use window, add ODBC Data Sources from Administrative Tools to your Java Derby driver and run jar.

Categories