1

Is there any way I can create Java projects using a simple text editor? Not an IDE like eclipse?

I want to be able to create .jar files without the assistance of an IDE, I have all the JDK commands installed already on my computer (such as javac)

I'd like to know what file structure I need, how I need to arrange my class files, what compilation steps I need to go through etc. to be able to create jar files.

theonlygusti
  • 11,032
  • 11
  • 64
  • 119

3 Answers3

3

Yes, completely doable (just not much fun once the project gets bigger).

I suggest if it's not a throwaway project, use a build tool like Maven or Gradle to manage your build process, so that you don't need to assemble classpaths and resources yourself, but still retain full control of the build and test lifecycle, without IDEs. This comes at a complexity cost, of course, but once it's set up life becomes easier.

See also How can I create an executable JAR with dependencies using Maven? or the Gradle docs about creating JARs

I'd highly recommend the standard Maven source directory layout too (src/main, src/test etc) as it's both commonplace and makes for easy integration with the above tools.

Community
  • 1
  • 1
declension
  • 4,110
  • 22
  • 25
2

Follow the below steps to create a jar file

  1. Compile the java source using javac

  2. Create a manifest file (if main exists) to identify main class

  3. Use the below command to create a jar file

jar -cvfm *.class

Shriram
  • 4,343
  • 8
  • 37
  • 64
0

Yeah. You can create your project structure without an IDE. But it's time consuming and you have to do everything.

To talk about creating JAR, you don't want any extra software. You can use jar utility, which comes with JDK.

Here are steps to create jar:

  1. Compile classes which you want to in jar
  2. Create manifest file (.mf). It's needed if you want to make jar as executable. If you want to bundle classes only together, then no need. (eg. Dependency jar)
  3. Go to command prompt and execute following command "jar cvf MyJarName.jar *.class". Make sure java is set in environment path and you're inside the directory of classes. cvf means "create a jar; show verbose output; specify the output jar file name.

That's all. If you want to include any folders inside jar then you can use folder name in above command after classes and it must be separated by space. Example: jar cvf TicTacToe.jar TicTacToe.class audio images

Dash
  • 9
  • 2