Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quickest method to package a Java console app

I've got a very small set of classes built up in a custom package hierarchy with one console app class that employs them. Everything works fine from JCreator and from a command prompt.

I'd like to build a second console app that re-uses that same package.

As a Java newbie, what is the quickest, dirtiest method to do that?

My main concern was avoiding copying the package directories over to the new console app's directory.

Using JCreator, I didn't have any problems adding the package directory to the project and compiling and running. But when I tried to run the console app from the command line, it couldn't find the classes in the package hierarchy.

In Visual Studio, you just add a reference...

like image 292
Rake36 Avatar asked Jan 24 '23 19:01

Rake36


1 Answers

What you want to do for both apps is create a jar file with a Main-class definition in the var manifest. There's a good bit of information on this in the Java Tutorials, but the gist of it is just that you'll create a jar file with the jar tool, and then make a little wrapper to run it as

java -jar myfile.jar
like image 188
Charlie Martin Avatar answered Jan 31 '23 23:01

Charlie Martin