Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-09-07
2
Medium Priority
?
368 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 120 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 255 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
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.
Suggested Courses

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