Creating JAR with NetBeans

I have several classes and folders with various media in it ( bmp, jpg, wav, ... ) that's included in my project. I want to create a jar file which contains this media. It's not a problem when i'm using console and typing "jar" commands. But can i do this from NetBeans, maybe include this media somehow ...
i have tryed this, and searched NetBeans help flies but there is no result. I'm just wondering if it's possible ?

I've a similar question.
I've created, by sql2java, this package
build\classes //contains .class file
build\javadoc //contains .html file
src\java //contains .java file
Now i want create a .jar file with all files inside.
How i can do this?
In Netbeans i've created a Library by Library manager. I've setted the corrispondent folder, and now the ide allow navigate .class file such as in a jar file. If i double click on one, the ide open corrispondent .java file, and if i want view javadoc, i right-click on .class file and choose "Show javadoc".
Well, how i can generate a jar file?
Thanks.

Similar Messages

  • Building JAR with NetBeans 4.1

    I have a NetBeans 4.1 project. I build a JAR file. So far so good.
    When I run:
    java -jar AmazonSample.jarI get, "java.lang.NoClassDefFoundError: javax/xml/rpc/ServiceException"
    Apparently, it can't find "jaxrpc.jar". This file is both in the root of the JAR file and I've also tried copying it to the current working directory next to the the JAR. I try;
    java -classpath .\jaxrpc.jar -jar AmazonSample.jarand
    java -classpath jaxrpc.jar -jar AmazonSample.jarI still get the same error. As an aside question, can you specify a classpath like that when running a JAR file?
    On other projects, I've added a classpath entry to the JAR's manifest file and that works fine. However, NetBeans doesn't provide an easy way to do that.
    This must be a very common scenario. How do I resolve?
    Thanks!

    If you put the jar files in a library and then add that library to compile
    and runtime classpaths its works fine running from within the
    netbeans but when you try to run the jar outside it doesn't workIt doesn't work because you aren't providing any classpath information. When you run using the -jar variant [java -jar <proggie>] or by clicking the jar in Windows, all external classpath information is disregarded.
    The only valid source for classpath information in that case is to provide it in the jar's manifest file, in the form of a Class-Path: <classpath> entry.
    To add this to a Netbeans-created jar, look for a file manifest.mf in the Project's files, and add the above entry to this file. NB constructs the actual manifest file from this file, and the classpath entry will transfer.
    Here's how to make this work:
    1. Create an empty directory test somewhere in the computer.
    2. Copy the external library directory or jar file to test.
    3. Add the line Class-Path: <name> (where name is the library's directory or jar name) to the manifiest.mf file. If multiple items need to be listed, separate them with a space - not a colon or semi-colon.
    CAUTION: The file must end with a linefeed/newline, and as far as I can determine, the <name> can't contain spaces.
    4. Build the Project in NB.
    5. Copy the jar it creates (in the dist directory) to test.
    6 From the test directory, either issue the java -jar <proggie> command or [in Window, assuming your machine is setup to do this] click/double-click the jar.
    The contents of test can be zipped for distribution; the recipent needs to unzip into a directory to run.

  • How to compile and creat JAR with native function

    Hi there,
    I wrote some native function for J2ME. But it seems like using J2ME wireless Toolkits, we can not compile native function. Is it right?
    Is anyone knowing how to compile and make JAR with J2MEWTK or command line?
    Thanks,
    Merry Christmas!!

    [zack327],
    JNI like or native interfaces APIs is not supported in the CLDC/MID Profile 1.0 specification. If you have J2ME code that includes JNI code, the J2MEWTK tool will not compile successfully for you.
    To package the compiled code to a MIDlet suite .jar file, use the 'Package' command in the J2MEWTK toolkit. It is found on the top menu bar 'Project' option as item on the dropdown list.
    To package the MIDlets into a MIDlet suite .jar file from the command line, you can execute the usual jar file command:
    jar cf MyMIDletSuite.jar Midlet.class
    You will also need to create a MIDlet .jad Application Descriptor file as well.
    HTH.
    Allen Lai
    Developer Technical Support
    SUN Microsystems
    http://www.sun.com/developers/support/

  • Create jar with nested jars progammatically

    Hello,
    I want to create a jar which will contain other (nested) jars, and then I want my main class (inside the created jar) to make use of classes within the nested jars. And all this, I want to do programmatically (e.g. using Runtime.exec()). Is this possible?
    Thanks,
    Edited by: 925181 on Apr 3, 2012 4:41 AM
    Edited by: 925181 on Apr 3, 2012 4:46 AM

    And all this, I want to do programmatically (e.g. using Runtime.exec()).I don't understand this part of the question. What will you be doing with Runtime.exec()?

  • Problems creating jar in netbeans - Failed to load main-class

    Hi,
    I was wondering if someone could help with a problem I'm having creating a jar. I have a project in netbeans 6.5 and used Netbeans' GUI Builder (matisse) to create some of the UI elements in the project. I've tried many times to do "Clean and Build" to build my project. It builds successfully, but the jar that gets created gives the following error:
    "Failed to load Main-Class manifest attribute from C:\... filepath here...."
    I checked the manifest file, and that contains:
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.7.1
    Created-By: 11.0-b16 (Sun Microsystems Inc.)
    I tried adding Main-Class: gui.MainGUI (which would be the class that contains my main function) to this file and tried running it again, but it then said "Invalid or corrupt Jarfile" when I try running it. MainGUI does exist in the Jar. I also tried with just Main-Class: MainGUI, same error.
    Does anyone know what I'm doing wrong? In NetBeans, if you go to the project properties, Main Class is specified as "gui.MainGUI" also, so that isn't the issue. Additionally, I have Swing Layout Extensions and Swing Application Framework included in the added libraries (required for the GUI builder, I think).
    Thanks for any help.

    Try creating a new Java project and be sure to choose project type Java Application.
    Copy source code to the newly created project and try again.

  • Problem to create jar with images

    Hello
    I have a project, it's a frame with a panel that contains a image, I want to create a Jar, but I have to problems, if create a Jar and execute out the project folder, I can't see the images, if I use getClass().getResource, I have other problems, I can't add panels.
    How it's difficult to say, I going to put a link from the project make with eclipse [My project|http://www.megaupload.com/?d=HBPHUWE9] , if someone wants have a look I would be grateful.
    http://www.megaupload.com/?d=HBPHUWE9
    Just look at the package com.constructor.interfaz
    To make the jar use the class InterfazFactoriaPaneles
    Thanks in advance !
    Edited by: Dav1d on Jul 10, 2009 6:11 AM
    Edited by: Dav1d on Jul 10, 2009 6:12 AM

    I explain better:
    I have a Class -> InterfazFactoriaPaneles, with this main
    public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        InterfazFactoriaPaneles application = new InterfazFactoriaPaneles();
                        application.getJFrame().setVisible(true);
    in the Frame I add a JPanel with an image, to load the image I override this method, where com.constructor.imagenes, it's the path where I've got my images :
    public void paintComponent(Graphics g){
              Dimension tamanio = getSize();                    
              ImageIcon     imagenFondo = new ImageIcon("./src/com/constructor/imagenes/patronConstructor.jpg");     
              g.drawImage(imagenFondo.getImage(),0,0,tamanio.width,tamanio.height,null);
              setOpaque(false);
              super.paintComponent(g);
    the with a menu, I remove the panel with the image I load other panel with components (JTextField, JTable, JLabel,...).
    If run the program from eclipse, everything it's ok, if I export into jar file, it works if the jar it's inside the project folder, but if I put the jar in other location, doens't load images, I google from answer and I read to put images path like that: new ImageIcon(getClass().getResource("/com/constructor/imagenes/patronConstructor.jpg")); , but if I do that, and run in eclipse, everything it's ok, but If I export into a Jar, I load the image, but when I try to change to other panel it doesn't work.
    So I do not what's the answer, if someone check my code, and try to make a jar, and the move the jar file into other location, will be able to see images doesn't appears.

  • Create jar with particular path

    I create a jar file using the API (package java.util.jar).
    My application works fine but it creates a jar and save this path (an example):
    fileA - c:\dir1\dir2\fileA
    fileB - c:\dir1\dir2\dirA\fileB
    How can I create a jar file and save this path ?
    fileA - fileA
    fileB - dirA\fileB
    Thanks in advance and sorry for my english.
    Matteo

    Alright, this package is not documented very well, so here's the help you need.
    The Zip entry, "ZipEntry" really doesn't care about the path like the file structure does. It just treats the path like a name, and when extracted with a program like unzip, the extractor creates the directories specified by the names, which are paths. You should always use relative paths in a zip archieve, and most programs will transform absolute path names just because it's dangerous.
    So here is a simple method that can zip up and directory tree, and take a base path off the start of the tree. In your example the arguments to this method would be...
    ("c:\\dir1\\dir2", new File("c:\\dir1\\dir2"), out)
    In this case the base and file are the same, because you didn't want any header directories. "out" is a ZipOutputStream that you created.... There is one problem though. I was a bad kid when I made this method, and it doesn't work on windows... so you're gona have to fix that before you can use it :)
       * Writes out all directories and contents of the given file
       * and all its decendents to the ZipOutputStream. Because it
       * it is unsafe and somewhat incorrect to use absolute paths
       * in ZipEnties, the base parameter must be non-null, have
       * length > 0 and start with a File.separator.
       * @param base The path to 'subtract' off the full path for
       * each file. For instance, if a file path is
       * "/home/joe/lovenotes/kelly.txt" and the base is "/home/joe"
       * Then the file would be placed under a ZipEntry of "lovenotes/kelly.txt"
       * @param file The file to start at. If it is a file, then it will be
       * the only entry written to the stream, otherwise, it will be recursed.
       * @param out The ZipOutputStream to write to.
       * @throws IOException if an underling IOException occurs, or if
       * a base condition is not met, such as the base not being the first part
       * of the file path.
      static private void writeTree(String base, File file, ZipOutputStream out)
        throws IOException {
        if(base == null || (!file.getCanonicalPath().startsWith(base))) {
          throw new IOException("parameter 'base' incorrect: '" + base);
        if(file.isFile()) {
          String path = file.getCanonicalPath();
          base = (base.endsWith(File.separator))
            ? base.substring(0, base.length() - 1) : base;
          // An Extra +1 so the path DOES NOT have a leading separator
          path = path.substring(base.length() + 1, path.length());
          if(DEBUG > 2)
            System.out.println(path);
          ZipEntry ze = new ZipEntry(path);
          ze.setSize(file.length());
          ze.setTime(file.lastModified());
          out.putNextEntry(ze);
          writeOutBuffer(createBufferFromFile(file), out);
          out.closeEntry();
        } else {
          File[] files = file.listFiles();
          for(int i = 0; i < files.length; i++) {
            writeTree(base, files, out);

  • Creating JAR in netbeans...

    I would like to convert all the java file to a jar file.
    I following the steps in netbeans. I double click the project name and click on the properties.
    I tick the compress JAR file and Build JAR after compiling column, but after compiling it, I can't find
    the jar file in the dist folder (i have asked it to save it to the dist folder).
    How can I solve it? Thanks
    (Posted in wrong forum before...-.-)

    Build the project.

  • NetBeans 4.1 Any luck creating jars?

    Has anybody had any luck creating executable jars with NetBeans 4.1?
    After trying to create an executable jar for about 6 hours I have come to the conclusion that 4.1 kinda sucks. I had better luck with 3.6. Although not intuitive it did have some instructions on how to do this.
    The manifest file that is created contains a comment " X-COMMENT: Main-Class will be added automatically by build" , so why isn't my main class added when I build the project? Did I not set my main class? It compiles and runs fine from the IDE so it obviously knows what the main class is.
    When I change the manifest and specify my main class ( as I did in 3.6 ) I get a could not find the main class error message.
    When searching for information I mostly get unanswered questions from other frustrated users. If anyone has had any luck with this, please , please let me know how it is supposed to be done.
    Thanks.

    To check, if this is an IDE or a project problem try to create a new executable project jar.
    To do this follow this procedure:
    1. Create a new Java project
    1.1 From the main menu select File->New Project->Choose Project->General->Java Application->Next
    1.2 Choose a name for the project (e.g. TestApp)
    1.3 Select [x] Set as Main Project
    1.4 Select [x] Create Main Class, give it a name (e.g. TestApp)
    1.5 Click on Finish
    2. Inside the created new project there is a new created class TestApp.java already with a public static void main(String[] args) method. Put something working there (e.g. System.out.println("Hello World!");
    3. In the Projects View on the left side right-click on the bold name of the project and select Properties
    4. In the popping up window select the bottom most entry, Run
    5. Behind the entry Main Class there should be one entry, TestApp. If not, you can use the button to the right, Browse... to locate any class with a main method inside your project to be the one executed.
    6. Click OK
    7. From the main menu select Build->Clean and Build Main Project
    8. After the output window displays "BUILD SUCCESSFUL (total time: <xxx> seconds)" you can switch to the shell window and execute the jar file with:
    java -jar TestApp.jar Of course you have to be carefull with the paths to java and to TestApp.jar
    9. The shell displays: Hello World!

  • How can I get a single jar file with NetBeans?

    How can I get a single jar file with NetBeans?
    When I create the project I get these files:
    dist/lib/libreria1.jar
    dist/lib/libreria2.jar
    dist/software.jar
    The libraries that have been imported to create the project are in separate folders:
    libreria1/libreria1.jar
    libreria2/libreria2.jar
    libreria1, libreria2, dist folders are all located inside the project folder.
    I added the following code to the build.xml:
    <target name="-post-jar">
    <jar jarfile="dist/software.jar">
    <zipfileset src="${dist.jar}" excludes="META-INF/*" />
    <zipfileset src="dist/lib/libreria1.jar" excludes="META-INF/*" />
    <zipfileset src="dist/lib/libreria2.jar" excludes="META-INF/*" />
    <manifest>
    <attribute name="Main-Class" value="pacco.classeprincipale"/>
    </manifest>
    </jar>
    </target>
    Of course there is also the project folder:
    src/pacco/classeprincipale.form
    src/pacco/classeprincipale.java
    Can you tell me what is wrong? The error message I get is as follows:
    C:...\build.xml:75: Problem creating jar: archive is not a ZIP archive BUILD FAILED (total time: 2 seconds)

    This is not a NetBeans forum, it is a JDeveloper forum. You might want to try http://forums.netbeans.org/. I also saw your other question - try looking in the New to Java forum: New To Java

  • .jar not working when building project with netbeans plugin and log4j

    hey..
    subject tells everything..if i build my project referencing log4j, i get a .jar file with 280 kb which is executable
    if i add log4j and do some logging, code still works in netbeans, but buildung produces a .jar with 80 kb and an
    attached lib-folder with the log4j.jar in it..if i uncheck copy requested libraries, i just get the 80 kb .jar file which
    is not working
    any hints?

    Are you building the jar file using the fxdeploy ant task to build the Jar? That is required to have an executable jar file.
    Also there was a change to the netbeans project structure, which may be a contributing factor.
    Things to try: Upgrade to the latest netbeans 7.1 beta build, set up a new Java platform in nb that includes JavaFX, create a new JavaFX project and build it. This should produce an executable jar.

  • How to create an API java with Netbeans???

    can you please help me on creating an api with netbeans and explaine me how can i make it communicate with existing platforms.thank's

    First please learn how to ask a reasonable question that is both answerable and framed in a way that someone here would want to answer it: [How To Ask Questions The Smart Way|http://www.catb.org/~esr/faqs/smart-questions.html]

  • Canvas3D not visable on Jpanel created with NetBeans UI Builder

    Hi,
    I created an application with NetBeans UI Builder. It has a frame and two panels. On one panel
    I attached a few things with the UI builder and they get displayed correctly. On the other panel however,
    I tried to attach a Canvas3D object that I created in another class (the object contains an universe
    with 3D objects) with not success by using the following code:
    DCL3DFrame mainWindow = new DCL3DFrame(); // object created with UI builder
                    DCL3d scope3d = new DCL3d(); // object created manually in another class
                    Canvas3D canvasForScope3D = scope3d.getCanvas();
                    mainWindow.getPanelForCanvas().add(canvasForScope3D, java.awt.BorderLayout.CENTER);
                    mainWindow.setVisible(true);I'm not a java programmer, so I'm probably missing something perhaps stupid.
    Any help is appreciated.
    Thanks,
    Salvo

    Thank you, now it works. It does not work because when I modified preferred size in netbeans the jpanel size was not changed. The jPanel size has changed when I reloaded(reopened) the file. I thought that preffered size property is not suitable but it is. I was wrong.
    Here is my working code.
    Regards,
    Primoz
    InvoiceCriteriaPanel icp = new InvoiceCriteriaPanel();
    jPanelCriteria.add(icp);
    jPanelCriteria.setPreferredSize(
          new Dimension(icp.getPreferredSize().width,
                                 icp.getPreferredSize().height));
    icp.setSize(icp.getPreferredSize().width,
                     icp.getPreferredSize().height);
    icp.setVisible(true);

  • Cannot create a project with netbeans 4.1

    hi. i am using jdk1.5 update 3 with netbeans 4.1. my operating system is ubuntu linux 5.04. when i want to create a new project with netbeans i get this error:
    javax.xml.transform.TransformerConfigurationException: Could not compile stylesheet
    i open netbeans, click button "new project", select "General > Java Application", click "next" button.
    project name: JavaApplication1
    project location: /home/bsevindi
    project folder: /home/bsevindi/JavaApplication1
    when i click "finish" button, i get the error above. what should i do? BTW, i have compiled
    a sample project and it works fine. the problem is only about creating a new project.

    I suggest you post the question to a netbean users forum.
    This forum is better for question regarding programming rather than how to use an IDE.

  • Trying to custom JSF created with NetBeans 5.5

    Hello,
    I'm trying to create an enterprise application using JSF new technology. I have find an easy way to do this with NetBeans 5.5 with SJSAS 9.0.
    I have an Apache Derby database connected and configurated with my enterprise application. I have created the Entity Classes from this database. JSF pages from Entity Classes are generated and persistence unit is configured successfully. All this steps had maked using NetBeans methods. I have feel a lot of tutorials and guides.
    When I play the enterprise application, a list of classes appears and you can obtain a list of the objects loaded into database of the selected class. When you have obtained this list of objects, you can create a new object or database row, you can view data of a selected object and finally edit this data.
    OK, now I would like to custom this JSF structure created with NetBeans. For example, I would like to call New.jsp page from any JSF class, from index.jsp. Always this error appears:
    java.lang.IllegalStateException: No FacesContext is available to process this request. This is most likely due to the request being sent to the wrong path.
    The same error I have obtained trying to copy-paste code from a JSF Page generated with NetBeans, the same exception appears only pasting this pice of code:
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
    <%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    </head>
    <body>
    <f:view>
    <h1><h:outputText value="JavaServer Faces" /></h1>
    </f:view>
    </body>
    </html>
    A way to solve this exception is using a JSF configuration. I have look for info about JSF configuration but I don't know how to configure faces-config.xml file. It seems is file where are configurated JSF enviroment: converted, managed beans and navigation rules are configurated by NetBeans.
    Could you please help me to custom this JSF NetBeans code?
    Or a tutorial or guide where JSF NetBeans 5.5 code is used with an enterprise application SJSAS 9.0 and a Apache Derby database.
    I have look for any example or possible solution during weeks but, I can't find anything that I can use to custom NetBeans code. All examples are too basic and never use an enterprise application.
    Thank you a lot!
    Kind regards,
    Ricard

    Thank you for reply.
    The web.xml configuration file is configured by NetBeans:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <context-param>
    <param-name>com.sun.faces.verifyObjects</param-name>
    <param-value>false</param-value>
    </context-param>
    <context-param>
    <param-name>com.sun.faces.validateXml</param-name>
    <param-value>true</param-value>
    </context-param>
    <context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
    </context-param>
    <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    <session-config>
    <session-timeout>
    30
    </session-timeout>
    </session-config>
    <welcome-file-list>
         <welcome-file>
    index.jsp
    </welcome-file>
    </welcome-file-list>
    </web-app>
    I think all info in the first post is necessary to explain my problem.
    Thank you to offer me a solution but, I don't understand you and I think there is no solution for my question:
    I would like to create a JSP like New.jsp created by NetBeans using JSF but, I won't to use New.jsp. How I can configure my enterprise application to use this new file?
    I'm sorry for my english, I explain better I know.
    Anyone understand my question? May you offer an example or guide or tutorial about this?
    Thank you!

Maybe you are looking for

  • ANN: Updated extensions for DW 8.0.2

    Adobe released the Dreamweaver 8.0.2 updater about a month ago, and since that time I have been working furiously on getting my incompatible extensions updated to work around the bugs introduced by the updater. In short, the Dreamweaver recordset fun

  • Connecting Studio Display 17' To iMac

    hey, my mom had a old mac with the silver tower. And she had a studio Display 17" and she just recently got a cinema dispaly and gave the screen to me. I am wondering what adapters i need to connect the Studio Display 17" TO my iMac G5. Thanks.

  • Flex swf cache issue in IE

    Hi, We are facing an important issue with the IE cache of the swf file. Could you please help us? For example, we built and put calendar.html & calendar.swf on server. We don't want users to download a 800 KB large swf file everytime when they access

  • Can anyone help me using these fonts?...

    Hi guys, im building a site in dreamweaver and was hoping to use the fonts - positive a, barnes and pen of truth. I know that there is something you can do with some copy and paste code from google but i cant seem to find it. Can anyone help?! Heres

  • User List with authority for T-Code

    Hello, I've to provide an overview (on regular basis) of users who have the authority for executing "Critical" T-Codes. The number of critical T-codes is around 30. I already checked transaction "S_BCE_68001400", but there i can only enter a single v