Pribhat
Pribhat

Reputation: 143

Converting .java to .jar or .exe for a SINGLE .java file

I've a single java file in my project which just fetches data from a SQL database and inserts it into Oracle database, it takes its input from a text file. The code runs perfectly, but now I am asked to make an .exe out of this java file.

I have googled and stackled for a solution but to no avail. All the questions and their respective answers deal with the Project as a WHOLE. I need to do it for just a single file. Also, I tried clean and build with NetBeans(on which I have written the java file) and it does make a .jar file, but is titled for the Project itself.

My project has some other java files which are totally unrelated. But I have kept them together as they are of the same type.

Any solution would be greatly appreciated!

Upvotes: 1

Views: 2312

Answers (3)

user3625525
user3625525

Reputation: 1

use the tool called Jsmooth. you can create a standalone .exe using it. and for creating a .jar file. In eclipse,

  • Go to file menu
  • select the EXport.. option
  • select "as runnable jar file".

Upvotes: 0

user784540
user784540

Reputation:

Create a new project in Netbeans.

Copy all jars, necessary to support the database connection to this new project from your existing big project. Upon specifying these jars in the probject settings as library jars make sure that they will be packaged along with the compiled java class.

Copy your java class that makes this database connection.

Compile and build the new project.

Convert the generated jar file to the exe, using a "java to exe wrapper".

For instance: Launch4J

that's it.

Upvotes: 1

ou_snaaksie
ou_snaaksie

Reputation: 28

Since it's just one file, why not copy and paste the code into a new project in NetBeans? This way you will leave your original project unchanged and compile your new project containing just the necessary code.

Upvotes: 0

Related Questions