Reputation: 493
I am trying to learn java and have implemented a single, and simple, class in Intellij IDEA 14.1.3. I want to be able to use this class in other projects without copy and pasting the class source into each project src directory. Essentially, I want to create a package, or module (I'm not sure which, which is part of the problem) that I can simply import into any projects's src that I am working on--kind of like my own, one-class, library. While trying to figure out how to do this, I came across the two following blog posts--
http://blog.jetbrains.com/idea/2011/10/new-in-11-create-library-from-project-view/ http://blog.jetbrains.com/idea/2010/08/quickly-create-jar-artifact/
--but when I tried to do what they instructed (creating artifacts in Project structure, etc.) I wasn't able to because my class doesn't have a main() method, as its not meant to. So I was wondering if I was going about this right--is there a way to do this, or am I stuck with copying and pasting?
Upvotes: 5
Views: 5873
Reputation: 493
I managed to get it--I had to go into Project Structure and set it to create a jar file containing my compiled .class file upon build. Then I could add the jar file as an external library in my other projects. Thanks guys for the replies.
Upvotes: 5
Reputation: 9437
You only need a main method if you want the package to be able to run as a standalone application.
So, to answer your question: no.
You don't need a main method to create a package, nor to import or use the package/library in a separate application.
Upvotes: 3