English 中文(简体)
名称中带有点的 Java 套件文件夹
原标题:Java package folders with a dot in the name

是否根据以下要求, 给定一个 MyClass.java 文件, 包含

package com.mycorp.foo;

public class MyClass {
  public static void main (String[] args) {
    System.out.println("Hello, world!");
  }
}

在以下路径中(注意文件夹名称中的点):

./com/mycorp.foo/MyClass.java

下列工作罚款:

$ javac com/mycorp.foo/MyClass.java

生产 ./com/mycorp.foo/MyClass.类 ,但以下不起作用:

$ java com.mycorp.foo.MyClass 
Exception in thread "main" java.lang.NoClassDefFoundError: com/mycorp/foo/MyClass
Caused by: java.lang.ClassNotFoundException: com.mycorp.foo.MyClass
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
最佳回答

类文件顶端提到的容器结构 < 坚固> 与汇编 < /坚固 > 关系较小,与 " 坚固 > 运行级别装载 < /坚固 > 关系更多。

  1. 您可以设置任何软件包名称并编译它, 例如, 在 Java 类编译之后

    package com.sa.test.me.yes.no;
    
     public class Test{
    
     public static void main(String[] args){
    
     System.out.println("Hello");
     }
    
      }
    

它编译< 坚固> 即使您不将软件包声明的 设置在文件夹结构中。 您可以通过不放置任何文件夹来测试它( 如 < code>java test.java ) 。

2. 软件包组织在组装货时更为重要。“强”类装载器

问题回答

http://docs.oracle.com/javase/tumental/java/package/managefiles.html" rel=“nofollow” > Oracle文件 指出,源树不必与对象文件树匹配。 javac 为此原因任其一,但 java 将要求目录结构遵循标准,即每个点分离的包件名称的元素有一个子目录。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签