Executable jar with package

Hello,
I have been making jar files and using the manif.txt. But today, I have the need to create a executable jar with a package.
eg: com.skp.util
I typed in my manifest.txt
Main-Class: com.skp.util.classname
(and made sure my return was there).
Then I jar cmf manifest.txt test.jar classname.class
But when I run it, I get a class not found error:
Thanks,
What does one need to do differently to get packages to work.

I tried that with a very simple class, but it does not appear to work?
When you run the jar do you use the package name there?
Here is all I have, it is simple:
mymanif.txt
Main-Class: com/ddi/ags/convert/showargs
Here is how I am crating the jar
jar cmf mymanif.txt test.jar showargs.class
And I run it like this:
java -jar test.jar
And get this error:
$ java -jar test.jar
Exception in thread "main" java.lang.NoClassDefFoundError: com/ddi/ags/convert/s
howargs
And here is the class:
package com.ddi.ags.convert;
import java.io.*;
import java.util.*;
public class showargs
File log_file = new File("C:/testlog.txt");
public static void main(String[] args) throws Exception {
     if (args.length < 1)
     System.out.println("args are less than one.");
     System.exit(1);
     } else {
     FileWriter writeit = new FileWriter("C:/testlog.txt", true);
     for (int i = 0; i < args.length; i++) {
          writeit.write(args[i] + "\n");
          System.out.println(args);
     writeit.close();
     System.out.println("all done with testing.");

Similar Messages

  • Run Executable Jar with MS Java VM

    I downloded an executable jar at work and tried to run it using the current MS Java VM (running on WIN98SE) without sucess.
    How do yo do this?

    from command line window:
    java -jar yourjarfile.jar
    (it runs only if the default class of the package have 'main')...
    p.s. very easy to find at google... ;)
    EOF

  • Executable Jar with -D internal

    I have created an executable jar file which works great. The program uses the users USERNAME and USERDOMAIN environment variables to log usage to a database. This works great when they use the command line of:
    java -DUSER=%USERNAME% -DDOMAIN=%USERDOMAIN% -jar c:\a.jar
    But my problem is that the users will sometimes just double click on the .jar file which will run the app but the environment variables are not available because the -D's were not included.
    Is there a way to update the manifest file so the -D options are always passed to the jar file?

    You can use System.getenv() under java 5.0

  • Running executable jar with additional classpath

    Hi,
    I have specified a classpath entry in my manifest file for library.jar and a main class entry for main.class in my myapp.jar archive.
    I can run myapp using
    java -jar myapp.jar
    when the library.jar is in the same directory like myapp.jar.
    Is there a way to put library.jar in another directory and still run myapp with something like
    java -classpath /path/to/library.jar -jar myapp.jar
    Background:
    I want to share library.jar for different jars in different locations and do not want to copy it to all those locations...
    Nils

    Is there a way to put library.jar in another
    directory and still run myapp with something like
    java -classpath /path/to/library.jar -jar myapp.jar
    When you use the -jar option of the java application launcher, the only Classpath that is used is the jar file or the Classpath specified by the Class-Path line in the mainifest of the jar.
    http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/java.html
    But, instead of using the -jar option, you can use the -classpath option and include all of the jars, including the jar with the main-method class.
    java -classpath /path/to/library.jar;path/to/myapp.jar myapp.jar.MainClass

  • Adding a jar to the classpath of an executable jar (mixing -jar and -cp)

    Hello,
    frankly I hesitated over posting this to "New to Java"; my apologies (but also, eternal gratefulness) if there is an ultra-simple answer I have overlooked...
    I integrate a black-box app (I'm not supposed to have the source) that comes packaged as an executable jar (with a Manifest.MF that specifies the main class and a bunch of dependent jars), along with a few dependent jars and a startup script. Long story short, the application code supports adding jars in the classpath, but I can't find a painless way to add a jar in its "classpath".
    The app's "vendor" (another department of my customer company) has a slow turnaround on support requests, so while waiting for their suggestion as to how exactly to integrate custom jars, I'm trying to find a solution at the pure Java level.
    The startup script features a "just run the jar" launch line:
    java -jar startup.jarI tried tweaking this line to add a custom jar in the classpath
    java -cp mycustomclasses.jar -jar startup.jarBut that didn't seem to work ( NoClassDefFound at the point where the extension class is supposed to be loaded).
    I tried various combination of order, -cp/-classpath, using the CLASSPATH environment variable,... and eventually gave up and devised a manual launch line, which obviously worked:
    java -cp startup.jar;dependency1.jar;dependency2.jar;mycustomclasses.jar fully.qualified.name.of.StartupClassI resent this approach though, which not only makes me have to know the main class of the app, but also forces me to specify all the dependencies explicitly (the whole content of the Manifest's class-path entry).
    I'm surprised there isn't another approach: really, can't I mix -jar and -cp options?
    - [url http://download.oracle.com/javase/6/docs/technotes/tools/windows/classpath.html]This document (apparently a bible on the CLASSPATH), pointed out by a repited forum member recently, does not document the -jar option.
    - the [url http://download.oracle.com/javase/tutorial/deployment/jar/run.html]Java tutorial describes how to use the -jar option, but does not mention how it could play along with -cp
    Thanks in advance, and best regards,
    J.
    Edited by: jduprez on Dec 7, 2010 11:35 PM
    Ahem, the "Java application launcher" page bundled with the JDK doc (http://download.oracle.com/javase/6/docs/technotes/tools/windows/java.html) specifies that +When you use [the -jar] option, the JAR file is the source of all user classes, and other user class path settings are ignored+
    So this behavior is deliberate indeed... my chances diminish to find a way around other than specifying the full classpath and main class...

    I would have thought that the main-class attribute of the JAR you name in the -jar option is the one that is executed.Then I still have the burden of copying that from the initial startup.jar's manifest. Slightly less annoying than copying the whole Class-path entry, but it's an impediment to integrating it as a "black-box".
    The 'cascading' behavior is implicit in the specification
    I know at least one regular in addition to me that would issue some irony about putting those terms together :o)
    Anyway, thank you for confirming the original issue, and merci beaucoup for your handy "wrapper" trick.
    I'll revisit the post markers once I've actually tried it.
    Best regards,
    Jérôme

  • Executable Jar Trouble

    Hello everyone,
    I am creating an executable jar with this command:
    jar cmf CarmaFrame.mf CarmaNew.jar *.*
    The contents of the manifest file (CarmaFrame.mf ) are:
    Manifest-Version: 1.0
    Class-Path: j.jar
    Main-Class: CarmaFrame.class
    This creates an executable jar in the directory that contains all of the files. It executes fine when double clicked in windows xp.
    If I move the newly created jar file to my desktop and try to double click it, I get this error:
    could not find the main class. program will exit.
    None of my java files are using packages. Any ideas on why I am having this problem?
    BTW, the j.jar file is a dependent jar file that does show it is in the CarmaNew.jar file when using the command:
    jar tf CarmaNew.jar
    Thanks,
    Brandon

    Packaging a jar within an executable jar:
    http://forum.java.sun.com/thread.jsp?forum=22&thread=405160&tstart=0
    http://forum.java.sun.com/thread.jsp?forum=22&thread=505248&tstart=0&trange=15
    http://forum.java.sun.com/thread.jsp?forum=4&thread=432114&tstart=0

  • How to create executable jar in eclipse using linking in compiler

    Hi,
    I have a project in Eclipse. I wrote already an ant build file for creating an executable jar which includes all project files.
    Now I want to create a second executable jar which is a subset of the project (a limited number of classes are necessary).
    I have a main class and I was looking for a way to generate a jar file which includes the main class and all the depending classes.
    Is there a way to do it? With ant or with another tool?
    Is it possible to compile a project given a main class, and include all depending classes?
    Regards,
    Biebel
    Edited by: biebel1975 on Jan 7, 2009 10:21 AM

    biebel1975 wrote:
    Some more information:
    When I compile all the classes, the jar file is +/- 3.5Mb inclusive the server side logic.
    The subproject I want to build, should be less then 1Mb (Only some screens and beans, no business logic ((only +/- 10% of the projects code) )).
    My question is: How can I create a executable jar with only the necessary class files which depends on the main class. (Linked with the imports).
    Is there a tool to do that? Can it be done with an ANT script? If so, how does the script looks?
    What are you talking about?
    You already said that you are using Ant.
    Ant uses script files.
    Since you have one with X items in it and you want something new with X-Y items in it the obviously it would make sense to construct an ant script that does less than the other ant script.
    The following provides a huge amount of information about Ant.
    [http://ant.apache.org/resources.html]
    Other than that no one can tell you want your Ant script will look like except that it will do less than the one that you already have.

  • Executable JAR witn anoter JAR

    Hello, I need some help to be able to create an Executable JAR from a project containing already one JAR
    Here is the situation :
    I've made a program who acceses Oracle DB and therefore I have integrated an External JAR (ojdc14_g.jar) in my project so I can get access to the classes needed to synchronize with the DB.
    I'm using Eclipse so I was able to generate automatically an auto-executable JAR. But the problem is that obviously the import statement :
    import oracle.jdbc.*;
    that I'm using to access the classes in the oracle External JAR is not undersood by the auto-executable JAR and I get :
    A fatal exception occured - Program will Exit
    Anyone an idea ??
    PS: the generation of auto-executable JAR with eclipse works perfectly with my other projects
    I'm using j2sdk 1.4.2.05
    Thanks in advance

    Hi guys!
    Sorry for the dot, I had missed that :(
    But still doesn't work.....
    I have been trying the following :
    Class-Path: . ./JarLibrary/ojdbc14_g.jar
    Class-Path: . /JarLibrary/ojdbc14_g.jar
    Class-Path: . JarLibrary/ojdbc14_g.jar
    Class-Path: . .\JarLibrary\ojdbc14_g.jar
    Class-Path: . \JarLibrary\ojdbc14_g.jar
    Class-Path: . JarLibrary\ojdbc14_g.jar
    and even
    Class-Path: . .JarLibrary.ojdbc14_g.jar
    Class-Path: . JarLibrary.ojdbc14_g.jar
    But I always get NoClassDefFoundError
    any ideas ? Could it be my java version ? I'm working with 1.4.2_05
    or any other ideas to be able to double-click on a Icon to run an Java application ?
    Hope I can give you those 10 Dukes soon

  • Create the executable jar's file

    Hi guys,
    I am working on java desktop's application where a user will be able to run the application by double click the executable jar file. I followed the description of "Creating and Deploying a Simple Archive to Your File System of the help. After creating the jar file and when I double click on jar file to run the application I got this error message "Could not find the main class. Program will exit". I was not also able to run the application on the dos command.
    Please help. I don't have any problem when I run from Jdeveloper 9.0.4. I have window XP professional.
    Your input will be very welcomed.

    OK open up your deployed Jar file in something like Winzip and have a look at the Manifest.MF in meta-inf\
    I've just created an executable JAR with a main class of mypackage1.Class1 and it all ran ok. Here's the manifest:
    Manifest-Version: 1.0
    Main-Class: mypackage1.Class1
    Created-By: Oracle9i JDeveloper 9.0.2So make sure your's is similar and your Main-class looks the same - e.g. does not say something like:
    Main-Class: mypackage1.Class1.class

  • Jtds classpath in executable jar

    how can i point to jtds-1.0.2.jar with classpath in an executable jar
    with just one class file it was this batch file:javac Dbase.java
    java -classpath .;jtds-1.0.2.jar Dbase
    pause

    ok i think i sorted it by making the batch file add a line to the manifest (it writes it anyway but i added Class-Path)
    echo Manifest-Version: 1.0>>MYMANIFEST.MF
    echo Main-Class: %strFileName%>>MYMANIFEST.MF
    echo Class-Path: . jtds-1.0.2.jar>>MYMANIFEST.MF
    echo Created-By: 1.5.0 (Sun Microsystems Inc.)>>MYMANIFEST.MFthe best source i found was this http://mindprod.com/jgloss/jar.html (right at the bottom of the page)
    that double clickable exe is nifty too, my m8s does that automatically cos its an executable but mine doesnt work like that even if i do open-with =S
    oh well, i just use batches neway =P

  • Packaging executable jars for my Swings based Desktop application

    I have developed a swings based desktop application for which we used third party JDIC jar inorder to incorporate the tray icon functionality for our application.
    The problem is i need to provide a distributable for this application and the application's executable jar file gets automatically created as a part of build from IDE [Am using NetBeans6.0]. The Application's exec.jar is not able to locate the jdic.jar and hence am unable to get the tray icon functionality, when i run the application's exec jar.
    i.I tried packaging the jdic lib jar with in the application's jar but got to know that tht can't solve the issue.
    ii.I also tried editing the manifest file to provide the class path to the thrid party jar [jdic] ... but of no use
    Any Help regarding this would be thoroughly appreciated.

    can anyone pls let me know how would i be able to package my application as distributable so that others can deploy and run.

  • Creating an executable jar-file including a custom package

    I am trying to learn how to create executable jar-files. I have managed this with a single class. However having a class which is an extention of another class which in turn belongs to custom package, I can't make it work.Running the program normally is not a problem. I don't think the problem is the actual code, but I will include it here anyway. I create the jar-file using:
    jar -cmf Direkt2b.txt Direkt2b.jar *.class
    where Direkt2b.txt is just:
    Main-Class: Diriekt2b
    Only the main class-file is included this way. Copying the other file to the same directory before creation doesn't help either. There is no error messages, the jar-file just refuses to run no matter what.
    The main-class:
    import java.awt.*;
    import extra.*;
    class Direkt2b extends ExtendedFrame {
         Font f;
         Direkt2b() {
              f = new Font("SansSerif", Font.BOLD, 24);
              setBackground(Color.yellow);
              setSize(400,150);
         public void paint(Graphics g) {
              g.setFont(f);
              g.setColor(Color.blue);
              g.drawString("V?lkommen till Java Direkt", 45, 100);
         public static void main (String[] arg) {
              Direkt2b d2 = new Direkt2b();
              d2.setVisible(true);
    The help-class:
    package extra;
    import java.awt.*;
    import java.awt.event.*;
    public class ExtendedFrame extends Frame {
         private static boolean first = true;
         private boolean isFirst = first;
         public ExtendedFrame() {
              addWindowListener(theListener);
              first=false;
         WindowAdapter theListener = new WindowAdapter () {
              public void windowClosing(WindowEvent e) {
              dispose();
              if (isFirst)
                   System.exit(0);
    }

    My problem wasn't really getting more than one class in a jar-file,
    but rather that my jar-file with multiple classes wouldn't execute.
    Reading the original post I realized that maybe I was unclear about that.
    However I have solved the problem now so for anybody reading this
    thread in the future I will tell you how.
    The general setting is this: You have a bunch of self-made help-classes
    organized in some classdirectory somewhere in the filesystem. You use these
    in your programming from time to time. You have set a classpath-varible
    in your OS such that Java could find your help-classes.
    Now you want to create executable jar-files so that you could publish your work.
    My problem was that while I added all needed classes in a jar-file, the main-class
    couldn't find the others because they were referenced incorrectly. The solution I
    came up with may not be elegant, but it works. I copied the main-class and all directories
    (only one in my case) just as they appear in the classpath-directory, to the same temporary
    directory. Then I created the jar-file from there, using: jar -cmfv Direkt2b.txt Direkt2b.jar Direkt2b.class extra/*.class
    I suspected that incorrect referencing was the problem and I tried several variations on the theme above
    before giving up and writing the first post. Part the problem was that I didn't get any error messages,
    just an annoying error-sound double-clicking the jar-file. I learned later that you could run jar-files from
    the command -prompt using: java -jar myjarfile.jar. This way you get a more useful response.
    I guess there is a way to include the classpath instead somehow, but I will use my method for now.
    I hope this was helpful to somebody.

  • How to use other jar with my executable

    Hello everybody
    I'm developing project in JBuilder which uses BC library "bcprov-jdk15-137.jar" This jar I got in reguired libraries section and it work fine in case that I run my application through JBuilder. Now I created executable jar file for my application but it works wrong. I don't know what dependencies shall I setup in JBuilder
    Can somebody help how can I run my application from jar file and I will use BC lilbrary without problem ?.
    What all shall I setup for correct work ?
    Thanks

    Hello
    I created new project(Frame application) in JBuilder 2006, Im using mentioned library therefore I put it into reguired libraries in project setting. When I run application through JBuilder (F9) it works fine.
    Now I would create executable jar file from my project, which will use this mentioned library. My project has one class CMTModule.class with main function. I created jar file via achrive wizard(AppletJAR). There are options of dependency rules in this wizard, so I choose Includes dependencies. Then I created manifest file and insert this item Main-Class: cmt.CMTModule.
    My application start but works wrong , I mean that there is problem with necessary library is not imported. How can I set up it in order to my executable jar can use this library without problems, because in JBuilder all works fine.
    What's is wrong ?
    Thanks

  • Issue with Packaged Jars added to project from resource Palette

    Hello!
    I am using Jdeveloper 11.1.2.2.
    I started this post thinking there was an issue having to do with packaging jars that refer to other libraries (see post Are Libraries Required?
    Now I realize it is a different issue (although that other post is relevant).
    Issue: I create a package -- a template in this case.
    I deploy it in my file system and then load it into the resource palette as a file system connection.
    I create a new application. From the resource palette, I add the jar to the view controller project, and am able to use the template in jsf files. No problem. Runs fine.
    then I load the application into subversion or I move the whole application to another directory on my computer.
    When I open the moved application (or do a checkout from subversion), I open the jsf that contains a reference to the jar, the design view is completely blank. Going to the source, I see my original code, but there are red signals in the upper-right signifying an error.
    If I run the application without fixing it, I get an error saying the template cant be found, Also, when I deployed to a standalone weblogic server, I get the same error (see the post above for this error).
    I open the project properties. The ADF Library is in the "Libraries and Classpath" and pressing edit, I can see the correct reference to the path of the jar.
    To make the application work, I have to remove the ADF Library (or at least the reference when pressing edit) and then from the resource palette, add it again to the project.
    IS THIS NORMAL? Am I doing something wrong with the initial packaging of the jar? Should I change some setting somewhere?
    How am I supposed to deploy to weblogic?
    The other posting shows an error output if I try to run the application before fixing the jar reference. I got the same darn error when deploying to weblogic.
    Would appreciate any help!
    Stuart
    Edited by: Stuart Fleming on Nov 18, 2012 4:45 AM

    Timo,
    thank you for your reply. I actually created a youtube video on this, available here: http://youtu.be/ERyLngq9hlI
    Since the video might be a little tedious to view, Here are the details. You can jump to the exciting parts of the video, if you want:
    Here is what I did:
    1. I cleaned out my system directory and the temp directory on my computer.
    2. Opened the application containing my template. Deleted the existing jar file.
    3. Started taking video....
    4. (From 40 seconds into the video) Created the jar file again.
    5. (2:55 minuts into video) Closed template applcation and Created new fusion application.
    6. (4 minutes into the video) Created model
    7. (4:15 minutes into video) in view controller added template, created a jsf page.
    8. (5 minutes into the video) Created Security and users.
    9. (6:30 minutes into the video) Created a task flow, with jsff in it, with a form on the jsff. Assigned Security to objects.
    *10. (7 minutes into the video). Ran JSF successfully.*
    11. (7:40 minutes into the video). Closed application. Copied the entire application into two directories.
    12. (8 minutes into video) Opened the first copied video. You can see that the jsf page is not accessing the template. Reviewed the View Controller project Libraries and classpath. Removed the library, re-added the jar from the resource palette. Worked fine.
    13. (9:30 minutes into video). Opened the 2nd copy of the file I intend for subversion. Showed the jsf page and the error it displays when open (same as in first copied application).
    Load application into subversion.
    14. (10 minutes into video). Check out application
    15. (10:15 minutes into video). Open JSF file. The reference to the template jar file is reading properly.
    16. (11 minutes into video). Load the original working copy into subversion.
    17. (11:30 minutes into video). Check out from subverion, but the check out failed.
    18. (12 minutes into video). Check out, and look at the jsf.  The page shows fine.
    Timo, I think this might be reported as a bug. You ought to be able to move files around on your computer. Also, the first time I checked the application out from subversion, the jsf page did not read the template.
    ALSO, when I tried to deploy the application (that contained the reference to the template jar file to weblogic), I got the same error when I ran the jsf
    first lines of that error:
    Error 500--Internal Server Error
    java.io.FileNotFoundException: /WEB-INF/ssfTemplate/SSFTemplate.jsf Not Found in ExternalContext as a Resource
    at com.sun.faces.facelets.impl.DefaultFaceletFactory.resolveURL(DefaultFaceletFactory.java:224)
    Thank you for your time and commitment!
    Stuart
    Edited by: Stuart Fleming on Nov 18, 2012 10:13 AM

  • Could not find the main class error with executable jar

    Hello,
    I have troubles creating an executable jar file and I ran out of ideas how to solve it so I would appreciate some help.
    I have created a jar file with the export function in eclipse
    the Manifest.MF file contains:
    Manifest-Version: 1.0
    Main-Class: view.AppTennisViewI tried starting the file with a batch file which contains following code:
    @echo off
    javaw -classpath c:\TennisHSQLDB_GC2\tennisApp.jar
    @start javaw -jar tennisApp.jar
    exitthe batch file and the jar are both located in c:\TennisHSQLDB_GC2.
    When i try command line I get the same result.
    I also tried alternate statements such as SET CLASSPATH iso javaw -classpath and including the classpath in the manifest file but no luck. It keeps given me the error: could not find the main class. program will exit
    Anyone any suggestions for my problem?

    nevermind, found it.
    classpath in manifest was incorrect

Maybe you are looking for