Help with packages in java - import does not work

I'm a C++ developer - not a java developer, but have to get this code working... I have 2 public classes that will be used by another product. I used the package directive in each of the java files. package com.company.thing; class MyClass ... When I try to compile a test app that uses that I add import com.company.thing.*; The javac compiler fails with errors about com.company does not exist. (even if I compile it in the same directory as the class files I just made a package of) I am sure I am doing something bone-headed and silly. I've read the http://java.sun.com/docs/books/tutorial/java/package/usepkgs.html pages and tried to set up a directory structure like /com/company/thing etc, but either I have totally screwed it all up or am missing something else. EDIT thanks for the suggestions - I had tried the classpath previously. It does not help. I tried compiling javac -classpath client.java and the result is: package com.company does not exist I have the code I want to import (the two java files) in \com\company\product\. I compile those fine. (they contain MyClass) I even made a jar file for them. I copied the jar file up to the parent directory. I then did (in the parent directory with the client java file) javac -cp *.java the result is: cannot access MyClass bad class file: MyClass.class(:MyClass.class) class file contains wrong class: com.company.product.MyClass Please remove or make sure it appears in the correct subdirectory of the classpath. EDIT I got the client code to compile and run if I used the fully qualified name for MyClass and compiled it in the parent directory. I am totally confused now. compiled with no classpath set - just javac *.java in the parent directory - and it worked fine. I can get a test app to compile, but that is not going to cut it when i have to integrate it into the production code. Still looking for help. EDIT: Finally - not sure why it didn't work before - but I cleaned up all the files all over the directory structure and now it works. Thanks

以上就是Help with packages in java - import does not work的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏