How do I import classes in a jar file?

I have the following directory structure, each directory is a seperate package of the same name as the directory
RPGUniversal
RPGMap
RPGCharacter
RPGCharacter is not done yet so I am ignoring that package for now.
RPGCharacter and RPGMap both depends on classes inside the RPGUniversal Package, but are independant of eachother and RPGUniversal is completely independant.
I want to place each package in it's own .jar file for use as a library in later programs.
I placed all the compiled classes for RPGUniversal inside the proper directory structure, I then used this command to place it in a jar:
jar -cf ./RPGUniversal.jar ./RPGUniversal/*
I then tested the contents with this command:
exodist@Abydos:/stuff/JProject/test$ jar -tf RPGUniversal.jar
META-INF/
META-INF/MANIFEST.MF
RPGUniversal/ADTs/
RPGUniversal/ADTs/t1.jpg
RPGUniversal/ADTs/t2.jpg
RPGUniversal/ADTs/t3.jpg
RPGUniversal/ADTs/t4.jpg
RPGUniversal/ADTs/Coordinates.class
RPGUniversal/ADTs/RPGImage.class
RPGUniversal/ADTs/FrameSet.class
RPGUniversal/ADTs/ImageTester.class
RPGUniversal/Exceptions/
RPGUniversal/Interfaces/
RPGUniversal/Interfaces/RPGCharacter.class
RPGUniversal/Interfaces/RPGItem.class
RPGUniversal/Interfaces/RPGObject.class
RPGUniversal/Interfaces/Trackable.class
RPGUniversal/Interfaces/Tracker.class
RPGUniversal/Interfaces/RPGMapComponent.class
RPGUniversal/Interfaces/RPGMap.class
so far all good, next I delete the RPGUniversal directory leaving the only file in the current directory RPGUniversal.jar
next I create the RPGMap directory and give it the proper .java files and directory tree.
I then run a script to compile every .java file
for i in `find ./ -name "*.java"`; do javac "$i"; done
and I get a ton of dependancy errors:
exodist@Abydos:/stuff/JProject/test$ for i in `find ./ -name "*.java"`; do javac "$i"; done
./RPGMap/BaseClasses/StaticMap.java:13: package RPGUniversal.Interfaces does not exist
import RPGUniversal.Interfaces.*;
^
./RPGMap/BaseClasses/StaticMap.java:20: cannot resolve symbol
symbol : class RPGMap
location: class RPGMap.BaseClasses.StaticMap
public abstract class StaticMap implements RPGMap
^
./RPGMap/ComponentClasses/MapTile.java:9: package RPGUniversal.Interfaces does not exist
import RPGUniversal.Interfaces.*;
^
./RPGMap/ComponentClasses/MapTile.java:10: package RPGUniversal.ADTs does not exist
import RPGUniversal.ADTs.*;
^
./RPGMap/ComponentClasses/MapTile.java:16: cannot resolve symbol
symbol : class RPGObject
location: class RPGMap.ComponentClasses.MapTile
public class MapTile implements RPGObject
^
./RPGMap/ComponentClasses/MapTile.java:19: cannot resolve symbol
symbol : class RPGImage
location: class RPGMap.ComponentClasses.MapTile
private RPGImage MyImage;
^
./RPGMap/ComponentClasses/MapTile.java:31: cannot resolve symbol
symbol : class Coordinates
location: class RPGMap.ComponentClasses.MapTile
public boolean CheckForCollision(Coordinates C)
....the list goes on........
how do I tell it to look inside the RPGUniversal.jar file to find the required classes?
here is a directory tree so you can see how it is set up:
ls -R1
RPGMap/
RPGUniversal.jar
./RPGMap:
BaseClasses/
ComponentClasses/
ExternalInterfaces/
HigherClasses/
InternalInterfaces/
./RPGMap/BaseClasses:
StaticMap.java
./RPGMap/ComponentClasses:
MapTable.java
MapTile.java
TableList.java
TileSet.java
./RPGMap/ExternalInterfaces:
./RPGMap/HigherClasses:
DynamicMap.java
./RPGMap/InternalInterfaces:

The JAR file needs to be in the compliers classpath : javac -classpath "$CLASSPATH:RPGUniversal.jar" "$i"

Similar Messages

  • How to combine the classes from 2 jar files into 1?

    Hi there
    I have got 2 jar files with the same name but the classes that they contain are different. So, I want to combine those 2 files into 1. Could anyone please tell me how to add the classes in a jar file to another jar file?
    Thanks for your help!
    From
    Edmund

    The jar utility allows you to extract files as well as put them into a jar. This is in the java docs.
    You might have to hand modify the manifest file if it was hand modified in the first place. All you should have to do is copy the text from one file to another. The manifest will have the same name so you will have to extract to different dirs so it isn't overwritten.
    Steps:
    -Create dir1 and dir2
    -Extract jar1 into dir1, Extract jar2 into dir2.
    -Manually examine manifests and combine if needed.
    -Copy files from one dir to another.
    -Use jar tool to create new jar.

  • How to add my class into rt.jar file?

    Hi, everyone!
    I am using WinRAR to extract the package rt.jar and added
    my class file to javax folder. Then I use jar c0vf to create
    a package. After that, I restart my WSAD4.0.2. But it seems
    that WSAD4.0.2 can not be started. (It stops at the welcome
    screen for a long time.)
    Anything wrong I have made? How to resolved the reouble?
    Cheers,
    George Ma

    Thanks!
    Do you know how to add .class file to a project of WSAD4.0.2?
    I use CLASSPATH, but always failed in IDE. But it works in
    command line environment. I want to use some classes in a
    .class file.
    Can you help?
    Cheers,
    George

  • How  to include the inner classes in a jar file in netbeans ide

    Dear java friends
    how to say to netbeans ide that it has to include the
    inner classes in the jar file.
    (i have one single applet class
    with two inner classes that show up
    in the build/classes file but not in the jar).
    The applet works in the viewer but not
    in the browser (I believe because the
    xxx$yyy etc should be in the jar)
    willemjav

    First, please stop posting the same question multiple times:
    Duplicate of http://forum.java.sun.com/thread.jspa?threadID=5269782&messageID=10127496#10127496
    with an answer.
    Second, If your problem is that you can't do this in NetBeans, you need to post to somewhere that provides NetBeans support - like the NetBeans website's mailing list. These forums do not support NetBeans (or any other IDE) - they are Java language forums.

  • How do I list all classes in a Jar file?

    How do I list all classes in a Jar file?

    Its no problem if the jar file contains classes, but I have an EAR file, which contains a jar-file, and I want to list all classes in that jar-file.
    I would like to do something like this:
    java.util.jar.JarFile jarfile = new java.util.jar.JarFile( new File("/meYear.ear"), true );
    java.util.jar.JarEntry jar = jarfile.getJarEntry( "myJar.jar" );
    // Cast it to a new JarFile:
    java.util.jar.JarFile newJar = (java.util.jar.JarFile)jar;
    But the method getEntry returns something like jarFile$JarEntry, if I try to class cast it I get an classCastException.

  • Can I create a JTA EntityManagerFactory in a utility class in a .jar file?

    I have utility classes in a .jar file inside of a .war file deployed in Glassfish 3.1. One of these utility classes, CredentialsUtil, needs to access a database. I can't inject an EntityManager into CredentialsUtil since it is not an EJB. (For security reasons I don't want to make CredentialsUtil an EJB. I want it to be a POJO.)
    In CredentialsUtil I need an EntityManagerFactory that is connected to a datasource defined in Glassfish. Here is the line from CredentialsUtil.java and from the persistence.xml both of which will be in the util.jar file:
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Credpu");
    <persistence-unit name="Credpu" transaction-type="JTA">
    I can't use RESOURCE_LOCAL since any changes to the datasource configuration must be done in Glassfish rather than changing persistence.xml.
    (The transaction context is not important in CredentialsUtil. It will be called by a WS-Security handler which may not have a transaction context.)
    Can I put the persistence.xml and the CredentialsUtil class that creates the EntityManagerFactory from it inside of the util.jar file (which will be in a .war), or do I have to move the class and a copy of the persistence.xml file out to the .war file? (I'll have to leave persistence.xml in the .jar file too since there are some @Entity in the .jar file. I don't know why but there are @Entity pojos in the .jar file.)
    I'd like to use the existing persistence.xml, but if I can't is there is a way to create an EntityManagerFactory (or EntityManager) that gets its datasource directly from Glassfish, ignoring persistence.xml?
    Thanks.

    Styles in Pages are saved in the documents (or templates). There is no easy method for adding a style to a built-in template (and it is strongly recommended that you do not tamper with them). You can open a built- in template, add your style and save it as a user template so that your new style will be standard in documents created from that template.

  • Accessing classes in external jar files

    I have a jar file called main. I want it to be able to acces the classes in another jar file say test.jar how do i do this.
    Thank you

    ok, if i have this right...
    you have 2 directories that hold 2 .jars, right?
    plugins/ -------- build/plugins .jar
    systemModuals/ ------- DiaryUI and Loader .jar
    Your main JAR is diary?
    Diary.jar
    you want Diary to run with the jars inside plugins and systemmoduals?
    you set the "class-path:" tag like this....
    write this manifest file. save it as Manifest.txt and put it in your home dir.
    Main-Class: YourMainClass
    Class-Path: Diary.jar plugins/this.jar systemmoduals/diaryui.jar
    <make sure to hit enter, go to the next line>
    command line to your parent directory.
    jar cmf Manifest.txt Diary.jar build/main/*.class
    you should be set to go.
    use
    jar xf META-INF/MANIFEST.MF
    to read the present manifest that netbeans has created
    if necessary

  • How to know if the current application jar file has been overwritten?

    When I overwrite a jar file that is being used, the buttons that call new windows stop responding silently but is there some check I can make from within the application to know if the jar file has been overwritten, so that I can warn the user to restart it?
    I know this sounds bad so let me explain why I would want this, if you don't care then skip everything below this point.
    I have close to a hundred of users executing Java applications from a central repository in the network. This is important because the applications are always changing and evolving so it's important that I only have to update one binary. I do most updates after work hours so I don't have a problem there but sometimes there are critical errors that need to be corrected immediately. Depending on the amount of people using an application it may be impractical to warn and wait for everyone to close it and make everyone else wait for that so I just overwrite the files that need to be updated and then warn everyone to restart the application. The result is that buttons that call for frames that haven't been called yet stop working silently. Some users already know what to do when that happens but I want a more graceful approach. I wanted to check for this situation from inside the application so that I could inform the user of the update and provide information on what to do next. Can I do this? I tried some try and catch blocks of code but I can't seem to catch anything when that happens.

    You can write your own class loader that loads classes from that jar file. Make sure it isn't on the class path and when you want to create an object from that jar file, call up your class loader to do that. (You only have to do that for your "top-level" objects, within those objects creating another object will automatically be done by your class loader.)
    Periodically check whether the jar has been modified. If it has, refresh the application by creating a new instance of your class loader and using that to create new instances of all your objects.
    But that sounds like a lot of work just to avoid setting up an emergency change procedure where you get everybody to close their applications.

  • How can i import contacts from a csv file to "iCloud Contacts"?

    How can I import contacts from a csv file to "iCloud Contacts"?

    The only way I know of to import cells from a csv file is by creating a new file.  But then you can select the desired cells and copy them to the other file.  I just did it to be sure it works.
    1. Create the new spreadsheet file via the upload command.
    2. Select the cells (table) that you want to move to the other file and press command+C (copy).
    3. Close the new file and open the existing file.
    4. Select the top/right cell of the area to receive the copied "table" and press commant+V (paste).
    I hope this is what you're trying to do!

  • Is it possible to call a class in a jar file from JNI environment?

    Hi
    Is it possible to call a class in a jar file from JNI environment?
    Thanks in advance.

    Could you explain a bit more what you are trying to do? (In other words, your question is vague.)
    o If your main program is written in C, you can use JNI to start a JVM, load classes from the jar of your choice, and call constructors and methods of the objects defined in the jar.
    o If your main program is java, and has been laoded from a jar, a JNI routine can call back into java to use the constructors and methods of classes defined in the jar(s).

  • How to extract the contents of the Jar file?

    Hello,
    Can anyone tell me how to extract the contents of the Jar file?
    An example will be highly appreciated.
    Thanks.

    From command line, or from within a java application?
    Kaj
    Btw. Why do you need to do it. You do know that you can add jars to the classpath and read resources from them without extracting the file?

  • HT2470 HOW CAN I IMPORT WORD , EXCEL, POWER POINT FILES TO MICROSOFT 2011 PRELOADED IN MY I Mac ?

    HOW CAN I IMPORT WORD , EXCEL, POWER POINT FILES TO MICROSOFT 2011 PRELOADED IN MY I Mac ?

    First, don't post in all caps. It's considered shouting and very rude. As for your issue, http://answers.microsoft.com/en-us/mac

  • I bought Numbers because my Excel files would not work with Mavericks. How can I import a non-functioning Excel file into numbers? (As of now, the file NAME transfers but data is not.) but

    I bought Numbers because my Excel files would not work with Mavericks. How can I import a non-functioning Excel file into numbers? (As of now, the file NAME transfers but data does not.)

    HI Dave,
    I'm surprised you get no message when you attempt opening the Excel document in Numbers.
    I'm assuming Numbers 3.1, since you are running Mavericks.
    Does the Numbers file that opens show any content?
    Does it contain a table?
    How large?
    Does it contain more than one tab (indicating more than one sheet)?
    Do those other tabs contain a table?
    Have you checked those tables for data content?
    There have been cases in the past of imported documents opening with white text on a white background, giving the appearance of containing nothing. Check for this by selecting a block of cells, then applying a Fill colour or a Text colour using the Format button (paintbrush).
    I'd also suggest attempting to open the Excel files using LibreOffice, which can be downloaded from the linked website.
    Regards,
    Barry

  • Is it possible to load classes from a jar file

    Using ClassLoader is it possible to load the classes from a jar file?

    URL[] u = new URL[1] ;
    u[0] = new URL( "file://" + jarLocation + jarFileName + "/" );
    URLClassLoader jLoader = new URLClassLoader( u );
    Object clsName = jLoader.loadClass( clsList.elementAt(i).toString() ).newInstance();
    I get this error message.
    java.lang.ClassNotFoundException: ExceptionTestCase
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
    // "file://" + fileLocation + fileName + "/" This works fine from a browser.
    Is there anything I am missing? Thanks for the reply.

  • Import a BPM project .jar file in jedevloper

    Hi,
    Can we import a BPM .jar file in jdeveloper, to regenrate the underlying code. this jar is having the BPM and SOA code.
    << the actual case is to import the deployed BPM .jar file project in jdeveloper. >>
    thanks,
    rps

    You can unjar the file in your machine so that you have the source code.
    Create a new BPM Application (make sure you name the project & process similar to what you have in the JAR).
    After that copy & replace the unjared contents into the folder under <applicationName>/<projectName> except for <projectName>.jpr (since this is not in the jar).
    try opening it from Jdev .. I could compile using a similar approach and open the BPM process too.
    You would need to deploy and test the functionality to be sure that this works.

Maybe you are looking for