I have been using IntelliJ to write a very short demo Java program. I want to take the demo and convert it into a jar file, so I can import it for use in another program. Here is the catch. I want to import the jar file in Textpad. It’s just a basic text editor. I cannot just import the jar file via a menu, and be done with it since the jar will not be used in an IDE like IntelliJ. I need to know the import line for the jar file, but I can’t figure it out. I supplied the image of the conversion to a jar as well as my attempt to import which didn’t work. How can I find the package for the jar file?
Asked
Active
Viewed 1,164 times
0
-
2There are 2 separate steps here. (1) You don't import JAR files (using the Java `import` keyword) - you import classes, using the fully qualified class name - where "fully qualified" means it includes the package name. In your case you do not have a package (based on your 1st screenshot) because `DemoProject` is a direct child of the `src` directory. Therefore the import statement would be `import DemoProject`. – andrewJames Jun 03 '21 at 01:06
-
(2) When you come to compile and run your `ImportStuff` program, you need to ensure the JAR file containing `DemoProject` is on the classpath. In other words, you ensure `javac` and `java` know where to find the JAR file. **But why are you using TextPad at all, given you are clearly already using a full-featured IDE, which takes care of a lot of this for you?** That piece is confusing. Just use IntelliJ to create the JAR. – andrewJames Jun 03 '21 at 01:06
-
The class path was good, but comment about fully qualified helped. Textpad will not work unless a package is specified, so I added one to the src folder in IntelliJ and it worked. Ty – Steven Jun 03 '21 at 01:44
-
Glad you solved it! Minor correction on my part: I should not have said _"you do not have a package"_ - I should have said _"you do not have a_ named _package"_. By default, classes with no explicit package name are placed in the _unnamed package_ - see [here](https://stackoverflow.com/questions/2335211/what-is-the-default-package-in-which-my-classes-are-put-if-i-dont-specify-it). – andrewJames Jun 03 '21 at 13:08
1 Answers
1
You need to know two things:
- The class name (DemoProject)
- The package name.
So in your TextPad view, you've shown the package name as "Demo". It actually has to be confirmed.
I'm not familiar enough with IntelliJ to know how to configure the package name - that is something you probably have control over when generating the .jar file.
The brute-force method I'd use would be:
- A .jar file is just a .zip file. View the .jar file in your favorite archive program.
- Examine the MANIFEST.MF file inside the META-INF folder. There might be something that suggests the package name (e.g. "Automatic-Module-Name:").
- There will be folders in the archive. The full path of the folders makes up the package name.
E.g. I found a random .jar file on my system. The MANIFEST.MF file says "Automatic-Module-Name: org.jetbrains.annotations". The path to the classes is org/jetbrains/annotations, so the package name is "org.jetbrains.annotations".

Kevin
- 398
- 2
- 7
-
Thanks! This and the previous post helped me a lot. I needed to use textpad for the project. Sorry to go old school lol – Steven Jun 03 '21 at 01:49