Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Creating a .jar file
Creating a .jar file [message #520295] Thu, 11 March 2010 20:32 Go to next message
classBoy Missing name is currently offline classBoy Missing nameFriend
Messages: 12
Registered: March 2010
Junior Member
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 22:19 Go to previous messageGo to next message
Vinicius Isola is currently offline Vinicius IsolaFriend
Messages: 40
Registered: March 2010
Location: Brazil
Member
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 22:22 Go to previous messageGo to next message
David Wegener is currently offline David WegenerFriend
Messages: 1445
Registered: July 2009
Senior Member
"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 19:24 Go to previous messageGo to next message
classBoy Missing name is currently offline classBoy Missing nameFriend
Messages: 12
Registered: March 2010
Junior Member
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 19:43 Go to previous messageGo to next message
David Wegener is currently offline David WegenerFriend
Messages: 1445
Registered: July 2009
Senior Member
"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 20:21 Go to previous messageGo to next message
Vinicius Isola is currently offline Vinicius IsolaFriend
Messages: 40
Registered: March 2010
Location: Brazil
Member
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 12:37 Go to previous message
classBoy Missing name is currently offline classBoy Missing nameFriend
Messages: 12
Registered: March 2010
Junior Member
Perfect thank you, solved!!!
Previous Topic:Heavily customising Getter/Setter creation?
Next Topic:method missing in jar file
Goto Forum:
  


Current Time: Fri Apr 26 11:08:44 GMT 2024

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

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

Back to the top