How do I deploy a Java program in Eclipse? - java

I have a program I am making for a friend. It contains one class, references two libraries (sqlite4java and poi by Apache), and sqlite4java contains many native libraries (.so, .dll, .jnilib) that are within my lib folder. The program also reads and writes from a swimTeam.db file.
My question is how do I package this all into one program that can be run cross-platform? I have tried exporting the project as a runnable jar, but when I ran it it couldn't access the native libraries because they weren't exported. Any idea how to do this?

First thing is create a java project remove all the java files and copy all the Jar file you need to import into that project.
now add the the created project to your working project as "project references" (right click on the project and click on properties)
now add all the Jars in the Java buildpath->libraries
now export your project as JAR. open it and make sure that all the JARs u need are in it.

Related

Importing .java and .class file gone wrong in eclipse

Recently I worked on a project on a mac, using eclipse. When I was done with the project I copied certain .java files and their corresponding .class files onto a USB drive and brought it to my personal computer. When I try to use the import feature on eclipse and import everything, my main method is not recognized by eclipse. It will work if I create a new eclipse "class" by the name I have in the program and copy paste the code. I have many classes so I can not do this for each one. Is there any way for me to change all .java/.class files into files that will be read by the system?
Thanks
An eclipse project contains a lot of meta information. Just open the project directory in a file browser, and have a closer look. There are files like .classpath for example.
When you just copy your source code, you leave all the meta information behind!
You should either copy the complete project directory, or simply use the export task to create a ZIP file of your project. (to later import that in other systems).
There is one other way you can do this. Just create a new project with the SAME EXACT PROJECT NAME that you did at school or wherever. After you create your project, go to your file explorer and navigate to the following place:
<"Directory to work-space">/<"Project Name">/src/
For ex: in Windows, it is Generally:
C:/Users/your_name/workspace/projectName/src
In here, copy all your ".java" files.
Now go to eclipse, right click on your project and hit refresh. You will find all your .java files there. Right-click on your project and hit "Run"->"Run as a Java Project". It should run! hope this helps.
PS: You do not need your class if you are executing it in Eclipse. Eclipse will create its own class files.

Decompile a Java project and compile

I am trying to decompile a java project(.jar) file and I am able to get .java files from it. Now how can I compile it back? I am able to add the .java files to Netbeans just as a single file.But how can I add it as a project add compile it? The project is a JavaFX project. So please help me on this.
There are many ways to achieve this, but I don't think you will be able to import the project inside the jar just out of the box ( in this case, out-of-the-jar ) like that.
We can use the most basic technique ( a bit dirty I admit ) but it works.
Extract the contents of the jar in a directory and decompile it like you done it before
Next, make an empty project inside netbeans ( with no src directory or anything )
Copy the contents of your decompiled project into this netbeans folder. You should now see a skeleton structure of some files. Note The poject is inisde netbeans but it is not a java project yet.
Edit the classpath of the netbeans project and add java library to make it into a Java netbeans project.
The other technique that I use sometimes is that I make all the project files required by the IDE (Eclipse in my case) manually and then tell eclipse to import the project. When eclipse finds all the required files ( .project, .classpath and all ), it imports into the IDE just fine
Create a JavaFX project in your IDE.
Decompile the jar to get the java files. The files will be places in
different folders and sub folders based on the packaging.
Put the folders as packages in the project created in step 1 above.
Clean and compile the project in your IDE.
P.S: Make sure you respect the license agreements if you are planning the use the decompiled and recompiled classes in your project.

Exporting android project to jar (that includes other jars)

I've written a Android Game Engine library and would like to export it to a jar file. I've tried to do this with the following:
export > Jar File > Finish
As soon as I add the jar to the build path of another Android project, I get a little box in my code saying:
The type foo cannot be resolved. It is indirectly
referenced from required .class files
I believe this is because my Game Engine library includes other libraries in forms of jars.
How can I add those jar files to my Game Engine jar file?
You can decompile the other jar file using JDui, take what you need, and add it to your library. It all depends on how big is what you need..
Also, check whether you are using proguard in the export. You would have to be careful on how to configure it.
I assuming you are using Eclipse. You also need to use Properties->Java Build Path->Libraries->Add Jar button to add your jar file to the target project

Distributable JAR not working

I created a project in Netbeans 7.1 on my netbook which uses Windows XP. I used the Clean and Build command which created the distributable JAR file in the /dist folder. When I double clicked the file it worked.
Now I sent the entire project folder to my desktop, which uses Windows 7 Ultimate 64 bit. When I double clicked the executable JAR I got an error saying:
Could Not find or load main class myapp.jar
I checked the manifest file and it contains the main class name. Of course, it was autogenerated by Netbeans.
What is going on?
The common mistake is to forget to also take the "layout" folder. If you have used specific features of Netbeans, such as bindings, in the "dist" you have the jar but also a folder with the name "layout" in it and you must also copy it with the jar file and put it at the same target place.
In my case it was a pity having to also send this folder so I decided to stop using binding and other specific stuff and used to reprogram things by hand. Now I only send the jar and it is working.
Note that you can easily know if you have specific features.
Open Netbeans and look in your project folder. There you'll have 2 folder, "Source Packages" and "libraries". Check in libraries. If you have only the JDK it is ok. If you have other libraries listed, then there will be the supplementary folder in the dist and you will have to send it with the Jar.
Hope it helps

How to add class-files to new java project

I'm tasked with converting an existing Java/C++ mixed web-application to pure Java, but I'm hampered by some missing Java sources (.java files) for which only the class-files are available. Fortunately I don't need to change anything in that code, just need to continue calling the methods.
I created a new Java Web Application project (using Netbeans); recreated the applet by copying it's sources in and got it working in a skeletal fashion, with the calls to classes & methods not in the sources commented out, but I am now stuck on how to add the class-files (of the missing sources) to this project.
(I'm new to Java, obviously) Any pointers on how I should proceed will be most welcome.
Package the .class files in a jar.
$ jar cvf my-library.jar the/package/*.class
Add this jar to the CLASSPATH of your project/application. In Netbeans:
go to the project view on your left
then right click on the library option,
then click add JAR/Folder option.
To add some source/code to your project, classic java project or webapp java project, you have to declare the path to the needed class/jar in the classpath variable.
If you are running your dynamic web project via eclipse, just add the path to the classpath tab in the "run configurations" of your server.
To learn more about classpath, see wikipedia.
The usual approach is to collect all these class files in a JAR file (use the jar tool) and put them on the classpath.
Different from C/C++, for Java you don't need the source code to these other pieces in order to compile the applet. There is enough information in the class file for the Java compiler to do what needs to be done.
So you can uncomment the calls to this code and follow the instructions in the other posts to put the class files on your project classpath.
In the Project window, right click on your project and select Properties. Go to the Libraries category. Then click Add JAR/Folder and select the location of your .class files.

Categories

Resources