开发者

Public Java Class or Jar

开发者 https://www.devze.com 2023-04-13 05:47 出处:网络
I\'m looking to create a universal logging file for all of my companies Java applications. I\'ve done something similiar in开发者_运维问答 C++, where you simply import the file.

I'm looking to create a universal logging file for all of my companies Java applications. I've done something similiar in开发者_运维问答 C++, where you simply import the file.

My question is, what is the most effective/efficent way to create a public Java file (basically what do you create it as, and then how do you reference it)? I'm assuming its by importing your own class or jar? Thanks!


It's not really clear what you mean, but it sounds like you're trying to create a library to be used by multiple applications.

I'd suggest that the other projects should simply refer to it as a jar file - whether they build that jar file from source or fetch one from some company-wide repository which is updated when the logging code changes is up to you. From the application code, you'd just import it as any other class - whether the class is found in a jar file or as a .java file is irrelevant in the consuming Java source code.

It's worth noting that there are already many other logging APIs for Java - I would think very carefully before you create a new one.


In Java you don't import the file you import the class. The class that is imported is either in a compiled .class file or packaged in a .jar file. By convention, package your logger utilities in a .jar and distribute that.

You import the class by name regardless if it's yet to be compiled from a source file or already packaged in a .jar.

0

精彩评论

暂无评论...
验证码 换一张
取 消