JAVA command line options -cp and -jar don't work together?

Running JSDK 1.4.2 under Windows. I have a Java application that tries to dynamically load a class name that the user enters as follows:
try {
classResult = java.lang.Class.forName(strFilterName);
catch (ExceptionInInitializerError e) {
strErrorMessage = "ExceptionInInitializerError loading class: " + strFilterName;
catch (LinkageError e) {
strErrorMessage = "LinkageError loading class: " + strFilterName;
catch (ClassNotFoundException e) {
strErrorMessage = "ClassNotFoundException loading class: " + strFilterName;
This works fine if the classes that make up my application are left as class files in the classpath, but fails to work if they have been collected and run from a JAR file. Note: I can even dynamically load the class when running from the JAR file, if the class I'm trying to load is within that JAR file too. The problem really occurrs when the dynamically loaded class is located someplace else in my classpath. I've tried using various combinations of the "-cp" and "-jar" Java command line options - but when loading and running from a JAR file - the "-cp" parameters seem to be ignored. Is this a bug? Has anyone ever seen this before?
I run my program from the JAR file using this command:
java -cp .;e:\entmgr\filters -jar EntMgr.jar
Where "e:\entmgr\filters" is where the class I'm trying to dynamically load is. (This class has no package name, but loads perfectly as long as I'm not running the application from the JAR file). The class name specified by the user has to be fully specified with a package name (if it has one).
I have tried forcing the "java.lang.Class.forName(strFilterName);" call to use the system class loader, the parent of the system class loaded, and even the null bootstrap class loader - all with no success.
I am suspecting that the class loader that is loading and running my main program from the JAR file, is just not paying any attention to the "-cp" parameter when the "-jar" parameter is present. Indeed, I have never seen any change in the failure, no matter what I put in the "-cp" parameter when using the JAR file.
When I run this without using the JAR file, here is the command I execute:
java -cp .;davidp\snmp;filters davidp.snmp.EntMgr
Where this is executed in a directory that has a "filters" and "davidp\snmp" directory. In this case, because the "filters" directory is in my class path - I can dynamically load my class from it using just its simple name (i.e. "TestTrapFilter").
So, is there some bug that precludes the "-cp" parameter from working correctly when the "-jar" parameter is used? Is there some other way to initialize or set up the classloader I'm using, so it can find things outside of the JAR file I'm running from? I would hope that it is possible to get the same behavior from my program, no matter if it is run from a JAR file or not.
Thanks for any assistence!
Dave

These posts are pretty old, but this page came up in a google search while I was having the same problem, so I thought I would throw my own (Later found) solution in.
The -cp and -jar options did not work together for me, but I later learned that they didn't really have to (and you don't have to mess with jar manifest files).
While on the command line, if you want to set a specific class path and also run a jar, all you need to do is add the jar to whatever extra class path you need to use in the -cp <arg>, and then specify which class you want run from inside the jar.
IE:
java -cp <YourSpecialClasspath>: <PathToJar> <ClassToRunInsideOfJar>
in my case it was like:
java -cp /home/user/WebRCP.jar:./StandaloneInstaller.jar InstallLoader
Remember to put a ":" in between the two arguments for the class path (-cp).
Hope this helps someone in the future,
-Josh

Similar Messages

  • Where is the documentation on the Java command line options.

    I know you can get them by running java.exe, but does Sun have a web page with a little more detail?

    Googling for
    java command line options site:java.sun.com
    Found this for 1.4. I imagine you should be able to find something similar for 5.0.
    http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/java.html

  • Command line options in executable jar

    Hello,
    On a win32 system I have an executable jar that the user dbl clicks to run.
    What I would like to do is maintain this simple dbl click to run but have command line options passed to the vm. ie I would like the dbl click to invoke
    javaw -Xms60m -Xmx120m -jar myjarfile.jar
    rather than just
    javaw -jar myjarfile.jar
    Can these options be placed in the jar files manifest? If so how? (I can't see how to do it)
    Many thanks
    Mike

    why not use special .jar tool to help you to save much
    of your time?
    Thanks for the idea but it really doesn't answer my question.
    Mike
    [Edited by: jdcforumadmin1 on Jun 24, 2002 1:39 PM]

  • Rotating logs and rdate don't work together

    Hi people,
    Recently I've noticed a problem with rotating logs and rdate. Since the server runs as a cronjob a 'rdate' command, web server logs are not rotated correctly.
    Archived log files only keep messages from the last hour (23-24), when they should keep the messages of the whole day.
    Servers without the 'rdate' cronjob keep archived messages properly.
    The magnus.conf line that configures the archives logs is:
    Init fn="flex-rotate-init" rotate-start="0000" rotate-interval="1440"
    and the crontab that runs rdate:
    10 20 * * * rdate mytimeserver
    What is the problem with archiving logs and running rdate??
    Thanks in advance,
    Juan Fuentes.

    This is a major screw-up on Apple’s part. Interesting that I just realized courtesy of MacIntouch that TM was NOT backing up my FileVaulted home folder. I use my MacBook Pro probably like most people. When I’m at home I’m behind a firewall. I leave the computer connected to my home network and I leave it open and on. I don’t log out ever! For security I do use the FileVault feature and I don’t use distant connections to my home network.
    There should be an option for TM to back up the open file vault directory just as if, frankly, someone would have access to it if they picked up my open computer and walked off with it. The owner has to have physical control of the computer. FileVault works if the computer is asleep and the wake log-on is enabled or if the computer is restarted. However, if my filevault is open and being used by me it should be available for a TM back-up.
    Interesting that Retrospect, with all its faults and promises of vaporware to come, WILL back up my MacBook FileVault.
    Apple should provide some type of option for this situation. On the fly decoding of the open FileVault directory so as to avoid a repeated total backup of the whole thing is the answer. It is the owner’s responsibility to keep the TM volume secure.

  • Time machine and filevault don't work together

    Let me get this straight....my files can either be safe from being stolen if I lose my laptop OR they can be safe from being lost when my hard drive dies, but they can't be safe from both at once?
    Seriously, FileVault is a great feature and so is Time Machine. Maybe someone at Apple can help them learn to live together?

    This is a major screw-up on Apple’s part. Interesting that I just realized courtesy of MacIntouch that TM was NOT backing up my FileVaulted home folder. I use my MacBook Pro probably like most people. When I’m at home I’m behind a firewall. I leave the computer connected to my home network and I leave it open and on. I don’t log out ever! For security I do use the FileVault feature and I don’t use distant connections to my home network.
    There should be an option for TM to back up the open file vault directory just as if, frankly, someone would have access to it if they picked up my open computer and walked off with it. The owner has to have physical control of the computer. FileVault works if the computer is asleep and the wake log-on is enabled or if the computer is restarted. However, if my filevault is open and being used by me it should be available for a TM back-up.
    Interesting that Retrospect, with all its faults and promises of vaporware to come, WILL back up my MacBook FileVault.
    Apple should provide some type of option for this situation. On the fly decoding of the open FileVault directory so as to avoid a repeated total backup of the whole thing is the answer. It is the owner’s responsibility to keep the TM volume secure.

  • Remot Control For Digital@nywhere ATSC and Vista Don't Work Together Very Well

    I have a Digital@nywhere ATSC tuner card w/remote.
    On Windows XP, the remote worked ok. On Windows Vista, the remote works only some of the time.
    On Windos XP, the BDA drivers and utilities on the install disk loaded fine. Not so with Vista.
    On Vista, the utilities on the install disk seem to load fine, but the BDA drivers fail.
    Loading the Vista Digital@nywhere utilities gets the tuner card to work, but has no drivers for the remote. Leaving me to load the utilities from the install disk, and and the BDA drivers from the Vista Digital@nywhere files. A rather tedious process, with the remote only functioning sometimes.
    I have tried every trick I can think of to get the remote control and Vista to work together, to no avail. I'm stumped.
    I'd rather not go out and buy a new tuner card, when the Digital@nywhere ATSC tuner card works fine on Vista. I'd just like to have a remote control that works fine too. But I don't.
    I hope an answer can be found for this problem.
    If I haven't been clear enough, just ask, and I'll try to explain things better.
    Thanks for any help that anyone can give.

    Are you using Media Center in Vista? If so, buy a Media Center remote, should work with no problems.

  • SLM2008 and SD2008 don't work together

    Has anyone trouble to get Linksys SLM2008 Managed and Linksys SD2008 Unmanaged to Work together? SD2008 LED Light is continously flashing at connected Port.

    Hi Erik,
    I am guessing this might be a new installation and still covered by phone support warranty..
    Please open a case with the Small Business Support center to determine the cause of the issue.
    http://www.cisco.com/en/US/support/tsd_cisco_small_business_support_center_contacts.html
    regards Dave

  • PlainDocument and JFormattedTextField don't work together

    Hello everyone,
    I wrote a PlainDocument only allowing a certain amount of numeric chars to be inserted. This works smoothly with a JTextField.
    The problem is, I need to get it running with a JFormattefTextField, where I added an InternationalFormatter. What happens is, that with each character stringToValue (in InternationalFormatter) is called, insertString (in PlainDocument) is only called on a commitEdit.
    Does anyone know how to change this behaviour?
    Thanks,
    Marc Johnen

    Once again from the java docs
    Warning: As the AbstractFormatter will typically install a DocumentFilter on the Document, and a NavigationFilter on the JFormattedTextField you should not install your own. If you do, you are likely to see odd behavior in that the editing policy of the AbstractFormatter will not be enforced.
    Rereading your post, I thing your international formatter is your conflict point.
    My advice is to use the JFormattedText field as is or don't use it.
    FYI: I tried using JFormattedTextField on my current project and the qa team pretty much hated the fell of it from the get go. I ended up pulling it and writing custome InputVerifier / DocumentFilters where I needed to limit input.
    Hope this helps,
    Todd

  • Some apps and music don't work together....

    So I have this issue with some apps not working with music because the music is stopped due to a in game video etc...... and you are unable to resume the music unless you exit the app....... I believe apple should fix this bug and let it work like the itouch where if you double tap home it opens the mini ipod control...... should let you get to that control even when music is paused......

    The iPhone includes the same function - double clicking the Home button with the following options:
    Home
    Phone Favorites
    iPod
    There is also an iPod Controls on/off selection.
    When on - when playing music, show iPod controls instead.
    So I have this issue with some apps not working with music because the music is stopped due to a in game video etc...... and you are unable to resume the music unless you exit the app.....
    This may be an issue for you, but this depends on the app. If an app includes sound, you can't use the app and play music at the same time.

  • SumParent and ParentAfter don't work together in EvDRE

    I am writing EvDRE input templates in BPC 5.1 SP4. When I turn sumparent on, with ALL,Parentafter as the expand options. Some of the totals get the wrong formula. This is a bug that was reported a long time ago and I was told it was fixed in SP3, however I am still seeing it in SP4.
    Can anyone using a later SP confirm whether this has now been fixed...
    Thanks
    David

    This issue was resolved in BPC 5.1 SP3 and subsequentky un-resolved in SP4. I know that in the BPC 7M SP3 release, this is again corrected.  It may have been corrected in BPC 5.1 SP8 as per the plan. I understand your pain, as this has been an open iten for me since last Jan.
    Hope this helps.

  • Wifi and 3g don't work together

    My wifi works great at work were there is nit 3G coverage, but at home I have 3g coverage and I have to shut off wifi to connect to the Internet or anything. What up with the conflict.

    I'm guessing then, that you cannot access your wireless at home and are trying to rely on 3G coverage to access the Internet? That makes it a completely different issue, however I don't know how WiFi can interfere with 3G, except that if your phone is trying to log into a WiFi network, logs in, but the WiFi isn't working right, then you would not be able to get 3G access unless you turn off WiFi.
    Am I viewing this correctly? So the real problem is your WiFi at home isn't working right?

  • Spaces and Exposé don´t work together properly in Leopard

    The very first time I activated Spaces, I defined four windows to be controlled with combined F8 key and right mouse button (the mouse being part of the Microsoft Optical Wireless Desktop 1000). But now I cannot use Exposé to open, say, Safari and Firefox in the window #3 - or any other combination of applications previously set to a same specific window in the Spaces preferences pane. I checked up on Microsoft keybord preference pane and the F9 to F11 keys are controlled by Mac OS, as it has been since Tiger. What´s the bug? My Mac OS version is 10.5.1.

    This issue was resolved in BPC 5.1 SP3 and subsequentky un-resolved in SP4. I know that in the BPC 7M SP3 release, this is again corrected.  It may have been corrected in BPC 5.1 SP8 as per the plan. I understand your pain, as this has been an open iten for me since last Jan.
    Hope this helps.

  • IPod Nano 5th Gen and pedometer don't work together.

    I am a first time iPod owner and bought a new 16 Gb Nano 5th Gen recently. Have been using it during a 5 Km walk every morning.
    When the pedometer is operating in the background, the music plays back slowly and on some sounds like bass drum thumps there's a trrr that shouldn't be there.
    The speed of playback is not consistently slow, if I hold iPod steady in my hand it plays normally then starts tp "play up" when walking. all is normal when I turn the pedometer off and just listen - on the same walk.
    Anyone seen this before?? I haven't tried to reset since I bought it new and began using it like above the next day so I am thinking this is some design problem rather than something that can be fixed. Any comments would be greatly appreciated. rgds. Viber

    Thanks deggie,
    That's good to know. i thought there might have been a design fault.
    I called Apple and they adviced me to do the standard reset. I.e. top switch back and forth and "Menu" + "Centre" buttons. Then the funny thing was, they insisted on me going out of the house for a 5 minute walk. All seemed fine when using pedometer and listening to music. I did think about resetting but since it was only a day old thought - what is there to reset??
    Anyway, tomorrow morning will be the real test, all is looking good so far, fingers crossed. rgds Viber

  • BubbleChart and CategoryAxis don't work together....

    I am trying to create a BubbleChart in my javafx2 application that has Strings on its axis.
    When I try using CategoryAxis to achieve this I get a runtime error
    java.lang.ClassCastException: javafx.scene.chart.CategoryAxis cannot be cast to javafx.scene.chart.NumberAxis
         at javafx.scene.chart.BubbleChart.layoutPlotChildren(BubbleChart.java:96)
         at javafx.scene.chart.XYChart.layoutChartChildren(XYChart.java:551)
         at javafx.scene.chart.Chart$1.layoutChildren(Chart.java:57)
    is there any other way to create a BubbleChart with categories rather then numbers on the axis?
    Regards,
    Hans

    The decompilation of the source suggests that there is no workaround:
    190 invokevirtual javafx.scene.chart.BubbleChart.getXAxis() : javafx.scene.chart.Axis [19]
    193 checkcast javafx.scene.chart.NumberAxis [32]
    196 invokevirtual javafx.scene.chart.NumberAxis.getScale() : double [33]
    199 invokestatic java.lang.Math.abs(double) : double [34]
    I'd file a bug.
    Karl

  • IOS7 and Siri don't work together

    After loading iOS7 Siri just keeps telling me she cannot process requests at this time.

    I have been having the exact same problem using my Motorola blue tooth hands free device in the car with IOS 7. It worked just fine with IOS 6. Usually, if I place a call with the actual number it will work.
    It seems as though Siri doesn't look up my Google Contacts correctly. I have an entry in favorites for "Home". When I say, "Please call home", Siri "cannot process any requests right now". Put if I place the call using the number Siri announces that it is calling me at home.
    Everything worked just fine under IOS 6. I cannot EVER remember Siri not being able to take any requests under IOS 6. I don't know if iCloud has a role iin the problem because I wasn't set up with iCloud under IOS 6. When I upgraded to IOS 7, I also configured iCloud.
    But that's not to say that Siri never works with my contacts. Sometimes it does.

Maybe you are looking for

  • Open VI Reference Function won't execute in multi process application

    I have a sub vi with Reentrant execution, and it has recursive call on some cases. It is very similar to OpenG VI "Read Key (Variant)__ogtk.vi", my sub vi works without any problem unit LabVIEW's Two Button Dialog is opened in other process loop. I h

  • Use Skype for a business. What is the best way to ...

    We have a new business that is starting and a lot of the work will be done by people in different parts of the United States. We would like to have incoming calls be to 1 number, and have them be able to select whom or which department they need. If

  • I need help tuning games on my imac

    okay I got a 24" iMac. 3.06C2D with the nvidia 8800GS. 500GB hard drive. came with 2GB of ram but I put in 2 more GBs and now it had 4GB. I wanted to do some gaming so I got a copy of with does vista ultimate 32bit and installed it with boot camp. on

  • Library File Structure Problem

    I have 3 partitions setup on my computer, one running OSX, one for WinXP and another FAT32 partition I use to store data which is used by both operating systems. I recently copied my music library to this partition and set iTunes to use this partitio

  • How to set snooze time

    Hi , Please let us know how to set snooze time to 5 mintues in Iphone5. At present it is having snooze interval of 10 minutues. We are able to see Snooze off / on but i need to reduce snooze time from 10 minutes to 5 minutes. Appreciate your valuable