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; class MyClass ... When I try to compile a test app that uses that I add import*; The javac compiler fails with errors about 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 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 and the result is: package 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: 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 答疑

评论 抢沙发

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

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