Do you really use your reverse domain for package naming in java? [closed]
For a long time ago, I have thought that, in java, reversing the domain you own for package naming is silly and awkward.
Which do you use for package naming in your projects?
Asked by: Wilson688 | Posted: 23-01-2022
Once you understand why the convention exists, it shouldn't feel silly or awkward in the least.
This scheme does two important things:
All of your code is contained in packages that no one else will collide with. You own your domain name, so it's isolated. If we didn't have this convention, many companies would have a "utilities" package, containing classes like "StringUtil", "MessageUtil" etc. These would quickly collide if you tried to use anyone else's code.
The "reverse" nature of it makes class-directory layout very narrow at the top level. If you expand a jar, you'll see "com", "org", "net", etc dirs, then under each of those the organization/company name.
(added in 2021) This is even more important nowadays when this type of package naming is used for third-party libraries which are pulled in transitively during builds and could easily conflict if the names were not unique. If everyone adheres to the same convention, there will be no accidental collisions.
(added in 2021) The same naming convention can be used for application ids on an app store to ensure uniqueness as well.
We usually don't expand jars, but in early java development, this was important because people used expanded dir structures for applets.
However, this is nice now as source code dir structures have a very "top-down" feel. You go from the most general (com, org, net...) to less general (company name) to more specific (project/product/lib name).Answered by: Anna369 | Posted: 24-02-2022
I actually think the reverse domain name package naming is one of the more brilliant conventions in Java.Answered by: Oliver919 | Posted: 24-02-2022
If it's just an internal project, and the code is unlikely to ever be reused, then I'd usually go with short, descriptive names.
However, if the code is to be used externally or reused in another project, then I tend to go with the reversed domain scheme. It makes sure there won't be any package name clashes.Answered by: Robert894 | Posted: 24-02-2022
I find it pretty silly myself. The com. part really adds nothing but 4 extra characters. Also, I think using the company name in the assembly / project name is also wrong. I've worked at too many places that merged with another company or simply renamed itself.Answered by: Alina843 | Posted: 24-02-2022
I think that this depends greatly on what sort of software is being written. For example, I develop internal systems for a small company, so I choose:
sub is usually one of
server. If I was working in a (commercial) software company, I'd be a lot more reluctant to use the
project bit because it's likely that what the app was called when the project started and what it is called when it finished are two completely separate things! Here's to:
Answered by: Charlie387 | Posted: 24-02-2022
I do this for all my projects, I've even taken it across to my .NET applications for namespaces.Answered by: Carlos977 | Posted: 24-02-2022
Yes, I use the reverse domain for the the start of the package, followed by the other administrative information (projects, departments, etc). The use of the domain minimizes the chance of collisions between vendors/companies/FOSS projects. My "data" package will not collide with another company's data package thanks to the domain.
I have also used the convention of dropping the tld for internal work or classes that are not meant for outside use (maybe undocumented support libraries, etc). This usually makes it clear to other developers that different rules or policies may apply to a block of code.
Using the reverse domain is a lot less chaotic than arbitrary namespaces that don't follow any rules or established pattern.Answered by: Miller197 | Posted: 24-02-2022
It is very useful and copied by others (e.g. XML Schema).
It is useful in the 'large' (given the WWW) but perhaps more so across departments (i.e. in the small). It may seem bloated for smaller projects but it acts like insurance: it's there when you need it later.Answered by: Clark578 | Posted: 24-02-2022
Creating an XML document using namespaces in Java
I am looking for example Java code that can construct an XML document that uses namespaces. I cannot seem to find anything using my normal favourite tool so was hoping someone may be able to help me out.
java - JAXB: How do I annotate classes so that they belong to different namespaces?
I want to have JAXB-annotated classes which would be marshalled/unmarshalled to different XML namespaces. What I need is something like: <someRootElement xmlns="urn:my:ns1" xmlns:a="urn:my:ns2" xmlns:b="urn:my:ns3"> <someElement/> <a:someElement/> <b:someElement/> </someRootElement> How can it be done? ...
java - Bypassing namespaces while copying an XML with XSLT
Starting from an XML with a default namespace: <Root> <A>foo</A> <B></B> <C>bar</C> </Root> I apply an XSLT to remove the 'C' element: <?xml version="1.0" ?> <xsl:stylesheet version="2.0" xmlns="http://www.w3.org/1999/XSL/Transform" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="ht...
java - how to remove the namespaces from the Element
I am working with org.w3c.xml java library and encountering a few difficulties performing a few tasks: I have an Element object; how can I remove namespaces from it and the predecessors? How can I create a Document without the namespaces? I have tried DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); docBuilderFactory.setNamespaceAware(false); Docume...
namespaces - Deployment problem with java axis2 web services
We are having a problem deploying our webservices, built in eclipse using java/axis2. On local boxes and development servers some namespaces are generated as xmlns:ax21 & xmlns:ax23. But when deployed to test servers are xmlns:23 & xmlns:24. All servers are using identical java installs. This is causing problems with client apps trying to attach. Can someone help? Wher...
Parse XML with XPath & namespaces in Java
Can you help me adjust this code so it manages to parse the XML? If I drop the XML namespace it works: String webXmlContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<foo xmlns=\"http://foo.bar/boo\"><bar>baz</bar></foo>"; DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setNamespaceAware(true); DocumentBuilde...
java - GWT + XML documents with namespaces
I'd like to get a quick overview of available solutions (libraries, ...) that allow me to work with XML documents with namespaces on a DOM level - in GWT's client side. Additionally, I'm looking for an XPath solution that can work on that DOM (even if it requires writing my own XPath Navigator). XML parsing and serialization isn't necessary on the client - this can be done on the server.
java - Dealing with shared namespaces with multiple WSDL's (xmlbeans)
I have five WSDL's that share namespaces, but not all of them. I generate client code out of them (databinding with XMLBeans). Seperately they compile fine. I create JAR files out of each generated client code. Once I try to use all JAR files within a project, I get naming / compile conflicts. I want to reuse as much as possible. Is there any smart way to deal with this (rather than giving each client an o...
java - Using CXF's wsdl2java, is there an easier way to generate package names from xml namespaces without version numbers?
I'm using Apache CXF's wsdl2java utility to create some JAXB objects and some web service code. The schema in my WSDL has a lot of namespaces with version numbers on the end. For example: http://example.org/sample/namespace/1.0 When CXF generates my JAXB objects the packages wind up with package names like this: org.example.sample.namespace.1_0 Since thi...
java - XJC generated namespaces
I am trying to generate java source files from a package of *.xsd files using the xjc code generation tool. The namespaces used in those *.xsd files are as follows: http://www.domain.com/foo/bar.x http://www.domain.com/foo/bar.x.y http://www.domain.com/foo/bar.x.y.z XJC produces packages as follows: com.domain....
Still can't find your answer? Check out these amazing Java communities for help...
Java Reddit Community | Java Help Reddit Community | Dev.to Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)