Solved

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

Posted on 2004-09-07
2
343 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

628 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