How can I deploy a Java database application? - java

I having some problems; I have Completed My Java Database Project in net-beans. I also use Java DB or Derby, mins embedded database for back-end. I run my Project and it is successfully runs and it works properly with derby database. I set the database location in my project.
Then, I have created a Project JAR file. This jar file present on my project sub-folder that is, dist folder and then I have run it. And it work but I have coped the jar file and paste another directory it runes but is not connect with derby database and also copied whole project and paste another directory. Yet it does not work, only jar file is worked but database is not work.
I also want to create an exe file of my project and run on another computer without having any kind of software on user machine. How I can build the database in my project. how I can attach database file in my project.
Can you tell me, what I do? And also help if, I am use a MySQL then I have need all above requirements. What will happen to me?

Looks like jar file generated by you doesn't include dependencies.
To generate a jar file with dependencies while building a jar:
Select "Extract required libraries into generated JAR" as you do the export.
Select "Extract required libraries into generated JAR" as you do the export.
You can use this runnable jar file as executable.

Related

How to execute commands of an application in jar when the app is placed in jar?

I have a project built by maven that needs to call commands of an application(named qvality). So I added the app into directory resources(myproject/src/main/resources/qvality). Then I package the project with jar. In code, I use this.getClass().getResource("/qvality").getPath() to obtain the app path. However, the way is failed because of the path problem. The path is /home/user/pipeline-reconstruction-1.0-SNAPSHOT.jar!/qvality using this.getClass().getResource("/qvality").getPath().
So I want to know how to get the correct path of the app in jar? Or is there a better way to implement my desire?
You need to open the .jar with winrar(or other software) and insert your file. because when you export your project the file in the res folder are not export in the jar file.

jar file is not executing unless the entire project is included in system

I have created the automation script in Selenium using Java in Eclipse and have created a jar file by navigating through Export->java->Runnable JAR file-> package required libraries into generated JAR.All this has been done in System A.
I am trying to run the jar file in System B.But unless I dont include the entire project folder into System B.The jar file is not executing.
My question is ,how to run jar file without including the entire project into System B..?

how to make .jar file in Eclipse MARS

I'm learning Hadoop under VMware now.(win7, 64) Due to some reason, I can't convert a .java file to .jar file under virtual machine, so I tried to create .jar file under Eclipse.
I'm currently using Eclipse MARS(4.5.1). I need to download something about fat jar, but I can't find it online.
My colleague copied his Eclipse software to me. It is already installed, so I copied the whole package. It is Eclipse Kepler. So I am running two Eclipse software on my computer now. will this cause some problem? (I saved projects seperately)
I can do the convert .jar file thing correctly on Eclipse Kepler now. But I still want to use MARS and delete the extra Eclipse.
thank you !
What you're looking for is the "Fat JAR" eclipse plugin.
Fat jar is a jar which contains all the classes used by the project including their referenced dependencies.
The plugin can enable the creation of such a jar.
In your case, however, Eclipse "Mars" & Eclipse "Kepler" include this functionality. The trick is to get to it...
Here's what you do in order to export a Fat JAR:
Right-click on the required Project and select "Export..." --> "Runnable JAR file".
Select the option which extracts libraries and specify the destination JAR file.
Launch configuration is used to execute this JAR with a predefined "Main" class (this is the "Runnable" part...) using "java -jar file.jar".
If you don't plan to - it won't matter.
(Optional) You can also "Save as ANT script" which, well..., generates XML ant script as well.
select project
select Export
Expand the Java node and select JAR file. Click Next
In the JAR File Specification page, select the resources that you want to export in the Select the resources to export field
.
Select the appropriate checkbox to specify whether you want to Export generated class files and resources or Export Java source
or go to http://www.codejava.net/ides/eclipse/how-to-create-jar-file-in-eclipse

How to create Jar file with external folders and Jars

I made a simple standard-lone java Application using Spring,Apache Camel,Activemq for processing messages.
Note: My Application don't have any GUI.
My project structure is in the following way.
SACLib folder have nearly 70 external jars(all Spring,Camel and Activemq corresponding jars).
It's working fine in Eclipse. SO Now We want to deploy into Jar file.I tried in Eclipse,But I didn't seen Rod1,Rod2,Copy1 and SACLib folders in my Jarfile.
after Deploying Jar, If I run FirstConsumer.java it runs Rod1-->ThMapInfratab1-2.exe file. For this I mention Real paths of .exe file.
How can I make Jar file with including all my folders.
Thanks
Well, this is a kind of work that is typically done with build automation tools like Apache Ant, Maven or Gradle, so you can investigate there if you want to make this happen automatically next time.
But, if you want to do it manually...
First, you project needs a META-INF folder where you will place a file called a MANIFEST.
That manifest contains a Main-Class entry pointing to you main class. You can read about this in the Java Tutorial: Setting Application's Entry Point.
But it can also contain a Class-Path entry, pointing to all other jars required by your application and that should be loaded by the executable jar.
You can read about it the Java Tutorial: Adding Classes to your Jar Class Path.
If you are building your executable jar with Eclipse, it will let you choose the MANIFEST file that you want to use during the creation process.
Now, if you want to use build automation tools, there are other answers here that explain how to do it:
Creating a bundle jar with ant
How to create executable jar with dependencies with Maven
How to export an executable jar in Gradle
simply using ant download it , and then make a build.xml file and put it
Here's an simple example of an ant target that will create a jar (named test.jar) that includes all jar files under the lib directory. Maybe this will solve your problem?
for using apache ant, see this
http://ant.apache.org/manual/using.html

I need some help concerning using 2 jar files in Java

Well I have 2 .jar files. The main jar file is the jar file for my whole project and the other .jar file being the MySql JDBC Connector.
Well basically whats happening right now is that when I build the project I have the one main .jar file with everything but the MySql JDBC Connector .jar file is inside the main jar file when it builds in NetBeans.
Now when I am just running the project from within NetBeans the MySql JDBC driver can be found inside the src/com/game/mysql folder that I have it in. But when I build the project the Java application cannot locate the JDBC driver from within the main jar file.
When I open the main jar file with WinRar I can see that the JDBC jar file is still in its /com/game/mysql/ folder. But why cant the Java application access it?
I have heard that nested .jar files are not supported in Java so Im thinking this might be the reason although Im not sure if thats true. Is there a way that I can make it so that the application can find the JDBC .jar file within the main jar file?
Also I have done the thing in NetBeans where you add the .jar file through right clicking project -> properties -> Library -> Add Folder/Jar. Thats what makes it work in the NetBeans run but still not the App build.
I have heard that nested .jar files are not supported in Java
More precise, classes in a JAR file which is packaged as a child JAR inside a main JAR are indeed by default invisible to classes in the main JAR.
You have basically 2 options:
Ship your application with 2 loose JARs: your.jar and mysql.jar and define the relative path to the mysql.jar in the Class-Path entry of the MANIFEST.MF file of your.jar.
Class-Path: mysql.jar
When you put both JARs in the same folder and execute your.jar by java -jar your.jar, then it will work.
Let your IDE repackage all loose classes of mysql.jar inside your.jar or add a special classloader which preloads the classes of any embedded JARs. Since I don't do Netbeans, I can't tell whether it supports it and if so, how to do it. In Eclipse, however, this is definitely possible. See also this answer.

Categories