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

Similar Messages

  • 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.");

  • 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

  • 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

  • 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

  • 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 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

  • 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

  • Problem with executable jar file

    Hi,
    I wrote a simple little xml based app in eclipse, it had xalan and xerces in build path. I created an executuable jar that ran fine on my machine; I was able to move it to different directories and launch it successfully, but when I put the jar file on a network directory and asked a coworker to try running it, they got a message that said it couldn't find the main class.
    how do you deal with that?
    thanks,
    bp

    they got a message that said it couldn't find the main class.
    Are you sure?
    If you are sure then none of the other responses will help.
    That error suggests one of the following
    1. The jar you moved is not the jar that you are running.
    2. Your co-workers did not execute it correctly.
    3. You do not have an executable jar (and you are not testing it correctly on your box.)
    How exectly did they run it?
    The standard double click will give an error about "Main-Class" with that specific text when you attempt to run a jar that is not in fact an executable jar.
    That error is NOT the same as the standard class not found error.

  • Storing data with executable JAR

    if I have an executable JAR that needs to read and write from a text file so that users can customize the program, can I put the text file or any kind of database inside the JAR or does it have to go outside. Also, what is the best way to store such data, in a database or in a text file?

    if I have an executable JAR that needs to read and
    write from a text file so that users can customize
    the program, can I put the text file or any kind of
    database inside the JAR or does it have to go
    outside. I think it's safe to say that you'd need to create a folder to keep your files in. i.e. the Jar won't get updated.
    Also, what is the best way to store such
    data, in a database or in a text file?Depends, a small amount of simple data should go in a flat file, .txt is fine, whatever. If you have lots of (possibly complex) data and relationships between the data, etc. then you'd likely use a database.

  • Need help with loading images in executable Jar

    Hi,
    I've developed an application using netbeans that needs to load and display images.
    I use netbeans Clean and Build function to create an executable Jar file. When I run the executable Jar file it runs fine but when I come to a section of the application that needs images it freezes and can't load the images.
    When I then return to netbeans the part of the program that did successfully run before Clean and Build doesn't work anymore and I get an error message saying Uncaught error fetching image:
    I use,
    URL url = getClass().getResource("images/image1.png");
    Image image1 = Toolkit.getDefaultToolkit().getImage(url);to load an image.
    Can someone tell me why, when I clean and build my project to create a JAR, my images fail to load.
    Should I be storing the images in a specific folder or something??
    Thanks

    I've opened the JAR using winzip and, for some reason, the JAR hasn't preserved my file structure. So, when I try to look for an image as follows:
    URL url = getClass().getResource("images/file1.png");
    Image img= Toolkit.getDefaultToolkit().getImage(url);The folder doesn't exist and so it can't find the image.
    Can someone tell me how to keep my file structure when I create the JAR or an alternative way to find the images within the JAR file.
    Cheers

Maybe you are looking for

  • BPM 11g integration with Business Activity Monitoring

    Hello, I'm trying to implement business indicators in a new project in Jdeveloper, and i want see the business indicators in the BAM portal, i alredy configure the BAM adapter in the IBM console and make all settings described in the tutorial, but wh

  • Flash content in a PDF question

    Hi, I have embeded a SWF into a PDF using InDesign CS3 and Acrobat Pro 8.1.7. The SWF displays and plays fine, I was able to set the psoter image in Acrobat and I set the border opion to no border. The only problem is that when a user clicks on the s

  • Slideshows? In Premiere Elements 12?

    I used to create slideshows using sound fx, music, and my stillimages (photos)....not video in my iMovie program. Then I burn them to DVD's and can share with others. Is it possible to do that in Adobe Premiere Elements 12? I downloaded the trail ver

  • BT has billed me for incomplete services!

    Dear Sir/Madam! I have received my bt router on 18.02.2015, paid for that 6.95, on same day my internet was supposed to work, however it wasn't, which means the service the bt was offering wasn't functional however you (bt) thinks that this is accept

  • Default values in EO's and DB

    Hi all, in my DB (Oracle 9i Rel.2) I can define default values. In an INSERT statement I can use the keyword 'default' to add the default value for this field. When I create my EOs, the default value is completely ignored. Of course I can modify my E