Solved

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

Posted on 2004-09-07
2
323 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
ID: 12001012
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
ID: 12002447
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
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…

831 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