Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Creating a .jar file
Creating a .jar file [message #520295] Thu, 11 March 2010 15:32 Go to next message
Eclipse UserFriend
Hi Developers.

My issue is this, i have some java files which i would like to export and use as .jar files.
All files contains classes, the files all ends with .java extention and are contained into a java project.
I've seen the Eclipse tutorial for this case which advise to use:
Click on project>Export>java>jar file>Save as("verkiezingen")>Location("desktop")

Indeed it seems successfull as i see on my desktop the .jar file and while exporting the final dialog box does not tell me "exported with warnings"
I then try to import the jar within a project like so:
Right click on project>Build Path> add external jar's>select jar
all good so far as i see the new item "Referenced package" under the usual "JRE system library"
If now, within the project i create a new class and start with import.verkiezingen;
it gives me an error message saying "The import verkiezingen cannot be resolved"
cant understand why, if i open the jar from the "Reference package" the classes are there.
I will paste the code of a class within the project i've tried to export initially as jar.

public class StemmachineException extends RuntimeException {
	
	public StemmachineException(){
		super();
	}
	
	public StemmachineException(String s){
		super(s);
	}
}


Thx guys
Re: Creating a .jar file [message #520321 is a reply to message #520295] Thu, 11 March 2010 17:19 Go to previous messageGo to next message
Eclipse UserFriend
Maybe your import is wrong.
If you are trying to import a class from inside a package you can add the class name to the import directive as:

import verkiezingen. StemmachineException;

or import the whole package:

import verkiezingen.*;

Or alternatively you can use Eclipse`s power to do that for you by coding normally and then going to the menu:

Source > Organize Imports
Re: Creating a .jar file [message #520324 is a reply to message #520295] Thu, 11 March 2010 17:22 Go to previous messageGo to next message
Eclipse UserFriend
"classBoy" <writetoenrico@gmail.com> wrote in message
news:hnbk1n$gfr$1@build.eclipse.org...
> Hi Developers.
>
> My issue is this, i have some java files which i would like to export and
> use as .jar files.
> All files contains classes, the files all ends with .java extention and
> are contained into a java project.
> I've seen the Eclipse tutorial for this case which advise to use: Click on
> project>Export>java>jar file>Save as("verkiezingen")>Location("desktop")
>
> Indeed it seems successfull as i see on my desktop the .jar file and while
> exporting the final dialog box does not tell me "exported with warnings"
> I then try to import the jar within a project like so:
> Right click on project>Build Path> add external jar's>select jar
> all good so far as i see the new item "Referenced package" under the usual
> "JRE system library"
> If now, within the project i create a new class and start with
> import.verkiezingen;
> it gives me an error message saying "The import verkiezingen cannot be
> resolved"
> cant understand why, if i open the jar from the "Reference package" the
> classes are there.
> I will paste the code of a class within the project i've tried to export
> initially as jar.
>
>
> public class StemmachineException extends RuntimeException {
>
> public StemmachineException(){
> super();
> }
>
> public StemmachineException(String s){
> super(s);
> }
> }
>
>
> Thx guys
>
This class doesn't have a package declaration. Did you leave it out of your
posting, or is this how the class is actually defined? This may be your
problem. I believe that classes in a package can't reference classes that
are not in a package. Also, what is the actual import statement in the file
that is receiving the error. You need to fully qualify names in import
statements or end them with a wildcard. The name has to match the package
plus the classname.
Re: Creating a .jar file [message #520552 is a reply to message #520324] Fri, 12 March 2010 14:24 Go to previous messageGo to next message
Eclipse UserFriend
No Real Name wrote on Thu, 11 March 2010 17:22
"classBoy" <writetoenrico@gmail.com> wrote in message
news:hnbk1n$gfr$1@build.eclipse.org...
> Hi Developers.
>
> My issue is this, i have some java files which i would like to export and
> use as .jar files.
> All files contains classes, the files all ends with .java extention and
> are contained into a java project.
> I've seen the Eclipse tutorial for this case which advise to use: Click on
> project>Export>java>jar file>Save as("verkiezingen")>Location("desktop")
>
> Indeed it seems successfull as i see on my desktop the .jar file and while
> exporting the final dialog box does not tell me "exported with warnings"
> I then try to import the jar within a project like so:
> Right click on project>Build Path> add external jar's>select jar
> all good so far as i see the new item "Referenced package" under the usual
> "JRE system library"
> If now, within the project i create a new class and start with
> import.verkiezingen;
> it gives me an error message saying "The import verkiezingen cannot be
> resolved"
> cant understand why, if i open the jar from the "Reference package" the
> classes are there.
> I will paste the code of a class within the project i've tried to export
> initially as jar.
>
>
> public class StemmachineException extends RuntimeException {
>
> public StemmachineException(){
> super();
> }
>
> public StemmachineException(String s){
> super(s);
> }
> }
>
>
> Thx guys
>
This class doesn't have a package declaration. Did you leave it out of your
posting, or is this how the class is actually defined? This may be your
problem. I believe that classes in a package can't reference classes that
are not in a package. Also, what is the actual import statement in the file
that is receiving the error. You need to fully qualify names in import
statements or end them with a wildcard. The name has to match the package
plus the classname.


Hi and thx for the reply
the import declaration i'm using is
import verkiezingen.*;

And it tells me that : "the import verkiezingen cannot be resolved";
if before exporting as jar all classes i add the package declaration:
package verkiezingen;

it immediatelly underline the package name in red giving me the error message: "the declared package "verkiezingen" does not match the expected package"" "
how do you normally create the package reference?

Re: Creating a .jar file [message #520564 is a reply to message #520552] Fri, 12 March 2010 14:43 Go to previous messageGo to next message
Eclipse UserFriend
"classBoy" <writetoenrico@gmail.com> wrote in message
news:hne4d3$4di$1@build.eclipse.org...
> No Real Name wrote on Thu, 11 March 2010 17:22
>> "classBoy" <writetoenrico@gmail.com> wrote in message
>> news:hnbk1n$gfr$1@build.eclipse.org...
>> > Hi Developers.
>> >
>> > My issue is this, i have some java files which i would like to export
>> > and use as .jar files.
>> > All files contains classes, the files all ends with .java extention and
>> > are contained into a java project.
>> > I've seen the Eclipse tutorial for this case which advise to use: Click
>> > on project>Export>java>jar file>Save
>> > as("verkiezingen")>Location("desktop")
>> >
>> > Indeed it seems successfull as i see on my desktop the .jar file and
>> > while exporting the final dialog box does not tell me "exported with
>> > warnings"
>> > I then try to import the jar within a project like so:
>> > Right click on project>Build Path> add external jar's>select jar
>> > all good so far as i see the new item "Referenced package" under the
>> > usual "JRE system library"
>> > If now, within the project i create a new class and start with
>> > import.verkiezingen;
>> > it gives me an error message saying "The import verkiezingen cannot be
>> > resolved"
>> > cant understand why, if i open the jar from the "Reference package" the
>> > classes are there.
>> > I will paste the code of a class within the project i've tried to
>> > export initially as jar.
>> >
>> >
>> > public class StemmachineException extends RuntimeException {
>> >
>> > public StemmachineException(){
>> > super();
>> > }
>> >
>> > public StemmachineException(String s){
>> > super(s);
>> > }
>> > }
>> >
>> >
>> > Thx guys
>> >
>> This class doesn't have a package declaration. Did you leave it out of
>> your posting, or is this how the class is actually defined? This may be
>> your problem. I believe that classes in a package can't reference
>> classes that are not in a package. Also, what is the actual import
>> statement in the file that is receiving the error. You need to fully
>> qualify names in import statements or end them with a wildcard. The name
>> has to match the package plus the classname.
>
>
> Hi and thx for the reply
> the import declaration i'm using is
> import verkiezingen.*;
>
> And it tells me that : "the import verkiezingen cannot be resolved";
> if before exporting as jar all classes i add the package declaration:
>
> package verkiezingen;
>
> it immediatelly underline the package name in red giving me the error
> message: "the declared package "verkiezingen" does not match the expected
> package"" "
> how do you normally create the package reference?
>
>
If you want the class to be in package verkiezingen, then you have to place
the source file in a directory called verkiezingen. This folder has to be
one level below the source file for the project.

Create a folder called verkiezingen in your source folder. Move the java
file into this directory.
Re: Creating a .jar file [message #520567 is a reply to message #520552] Fri, 12 March 2010 15:21 Go to previous messageGo to next message
Eclipse UserFriend
The project name is not a package. And you can't import classes from the default package (no name) from inside a jar file. You can read more about that here: http://dev.eclipse.org/newslists/news.eclipse.tools.jdt/msg1 1016.html

To create the package you can right-click your src folder and choose New ... > Package
Set the name you want to it and then just drag you class into it. Eclipse will automatically refactor, adding the package declaration.

Adding the package declaration manually doesn't work because the file must be inside the folder structure that the package represents.
icon14.gif  Re: Creating a .jar file [message #520620 is a reply to message #520567] Sat, 13 March 2010 07:37 Go to previous message
Eclipse UserFriend
Perfect thank you, solved!!!
Previous Topic:Heavily customising Getter/Setter creation?
Next Topic:method missing in jar file
Goto Forum:
  


Current Time: Tue Apr 15 01:58:07 EDT 2025

Powered by FUDForum. Page generated in 0.03448 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top