Solved

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

Posted on 2004-09-07
2
316 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

929 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

13 Experts available now in Live!

Get 1:1 Help Now