I am trying for a while to make executable JAVA application having embedded DB (derby DB), but facing some problems, and need your valuable help.
Namely, I am using Eclipse as environment.
I export Java app to RUNNABLE JAR file, and it works fine on my desktop machine.
The idea is to make EXE doubleclick icon and send it to another machine which have no JAVA background/environment....so point is to send it to another user who will just get exe file, double click it and work with it.
The DB is not only readable, since application is inserting data in tables.
So, it works fine on my machine, but when I send the same JAR file to another machine, I get error:
"Schema TEST does not exist"
I can see application but without any data, like there is no connection with DB. So, it is useless.
Even I use JSmooth, Install4j.... to convert JAR to exe file, I get the same error.
So, first I have to make JAR file working on another machine.
Seems to me, I am doing something wrong with DB files.
Please let me know what info u need more from my side, and let me know how I can do this.
If the application intends to read AND WRITE data when it is running, then it can't be entirely contained in a JAR file, because you can't put an updatable Derby database in a JAR file. You'll need to have some "installation procedure", perhaps some logic that you run the first time your application is double-clicked by the user, that (a) finds a suitable location for the Derby database on the user's machine, (b) creates the database and defines all the tables, views, etc, (c) loads any initial data.
Then, on subsequent runs of the application, it will be able to re-open the database and continue using it.
Related
I have written an JavaFX application to study German language with a Flashcard like program. It turned out my classmate also want this but I don't know how to deploy it.
I have a sqlite database which store some german words and I need read/write access. I have tried hardcode the path but it obviously is not good. I have tried to load the sqlite file by the following line and deploy it as a runnable jar but I couldn't write on it.
"jdbc:sqlite::resource:Vokabeln.sqlite"
Assume that I don't want to make remote web application, how should I make this file available to my code, and is platform independent? Should I make a installer program so that I ask the user what is the path? I also don't know how to write an installer application. I googled and didn't find anything like that.
You'll want to distribute your application with the database as a file outside of the Jar because otherwise you won't be able to have write access to it.
If the database file is on the same directory/folder as the Jar file, you should be able to connect to it with a JDBC URL like the following: jdbc:sqlite:sample.db
Distributing your application as a Zip file is fine, but if you can't expect end users to have Java installed and so, there are programs to create installers, even cross-platform, such as IzPack and Install4J
I have created javaFX project with embedded database H2. And I have created jar. On my computer this programm works. And on other computer this programm runs but buttons doesn't work. I think they dont work because project doesn't see database. I cant understand how to build project right with dependencies(database). Plz help me to build jar with database!!
P.S. I dont know how to use maven.
This might not be the solution to the root cause of your problem, but to include a database in a jar file can be done in the following way:
Theory: Execute a script that creates and populates the database when the application starts. This should be done only once, on the first execution. Further executions should use the existing database and data.
How To: use flyway or another tool to executes the script automatically calling a simple method.
I created a java project that uses a database to retrieve, edit, and save data. I finished the project using Netbeans and now I want to create an installation out of the project. To do so, I want to include the database to be installed along with the project. The code I am using to connect to the database is:
Class.forName("org.h2.Driver");
Connection con = DriverManager.getConnection("jdbc:h2:~/localhost/gallerie", "root", "123");
The application is working fine on my pc, but I need it to be installed as an executable on other pcs.
What is the best way to do so?
One way to do this is with the setup packager from stardust software. You will also need to include some script or some Java code to create the database and the database user. You don't need to do that with the installer. Instead, create some file or store something using the Preferences API so the program knows when it is running for the first time. When your program runs for the first time it needs to call some function to create the database user and the database.
Alternatively, you could also package the database files with your application as described by this stack overflow question.
I have to create a jar with a java application that fulfills the following features:
There are xml data packed in the jar which are read the first time the application is started. with every consecutive start of the application the data are loaded from a dynamically created binary file.
A customer should not be able to reset the application to its primary state (e.g. if the binary file gets deleted for some reason, the application should fail to run again and give an error message).
All this should not depend on the os it is running on (which means e.g. setting a registry entry in windows won't do the job)
Summarizing I want to prevent a once started application to be reset in order to limit illegitimate reuse of the application.
Now to my ideas on how to accomplish that:
Delete the xml from the jar at the first run (so far I came to the understanding that it is not possible to let an application edit it's own jar. is that true?)
Set a variable/property/setting/whatever in the jar permanently at the first run (is that possible)
Any suggestions/ideas on how to accomplish that?
update:
I did not find a solution for this exact problem, but I found a simple workaround: along with my software I ship a certain file which gets changed after the program is started the first time. of course if someone keeps a copy of the original file he can always replace it and start over.
Any user able to delete the binary file, will, with enough time, also be able to revert any changes made in the jar. When the only existing part of the application is in the hand of the user, you won't able to prevent changes to it.
You can easily just store a backup of the original jar, make a copy, use that for one run, delete, copy the original jar, etc. You would need some sort of mechanism outside the users machine, like an activation server. The user gets one code to activate an account, and can't use that code again.
I have a (for me complex) problem, but wil try to address only 1 issue in this thread.
I have a java application that has a MySQL database in the backend.
I want to be able to deliver the application along with the database preferebly via an installer (this is also a part I have not currently a solution).
Anyway the problem for now, is that my preference is that MySQL should not be installed as a service.
My reason is that I would prefer not to modify the machine, that my application will be deployed.
I prefer to deliver a "self-contained" application.
So if MySQL is not installed as a service, then it must be started somehow.
I know that I can start MySQL as a standalone using:
mysqld --standalone --console
In this case a new command line window opens and MySQL runs (I used it so far during development/code testing).
I don't know though how I can achieve the same effect once the application is deployed (and start MySQL via code at runtime).
I thought of using the Runtime and do something like:
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("PATH\\mysqld --standalone --console"); //PATH is of course the appropriate path to MySQL installation
But this does not seem to do anything. It just remains hunging.
Ideally I would like to start MySQL and also not have a concole open.
Is there a solution to my problem?
Why do you want to make your life hard? Don't use MySQL, instead use an Embedded Database, such as:
H2
HyperSQL
Apache Derby
Check MySQL Connector/MXJ. You can download it from here.It gives complete control over start and stop of database.Once you download and extract the zip, check ConnectorMXJObjectTestExample.java under 'src' folder. It will give you complete idea.