Solved

Not simple - How to package Java class in the Eclipse?

Posted on 2004-09-07
2
311 Views
Last Modified: 2010-03-31
Hi there,

I know it is a simple question - I cannot figure it out, please help me. I create a Eclipse project for my regular Java class development. I want my classes to be packaged in a JAR file. Thus I create a directory hierarchy and let the Eclipse create a class for me like this (I set the package name as myTest.src when creating the class):

package myTest.src;

public class Test
{
   public Test()
   {
      super();
      // TODO Auto-generated constructor stub
   }
   public static void main(String[] args)
   {
   }
}

However, The Eclipse complains "The declared  package does not match the expected package". The class is created by the Eclipse and the package code is made by the Eclipse too. Why it is still complaining? I tried to package the class to single level such as package myTest. It works.

It seems there is a trick to package java classes in multi-level with the Eclipse. Could anyone tell me how to do it?

Thank you,

XWL
0
Comment
Question by:XWL
2 Comments
 
LVL 19

Assisted Solution

by:ramazanyich
ramazanyich earned 40 total points
Comment Utility
did you created a directory myTest or mytest ?
Check case sensitivity of your directory and package definition.
By the way, package names usually named in lowercase letters.
0
 
LVL 2

Accepted Solution

by:
gen718 earned 85 total points
Comment Utility
Eclipse will create the mytest and myTest/src directory for you when you compile.

Make sure that you rename the package in the package explorer area of Eclipse to myTest.src .

That should fix it.

You can create the jar file via the Export menu item.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now