Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com How to run jar files from another file disk?

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 01-03-2012, 04:27 AM PM User | #1 Apothem Regular Coder     Join Date: Mar 2008 Posts: 380 Thanks: 36 Thanked 25 Times in 25 Posts How to run jar files from another file disk? So I have two file disks (I think that's the right terminology): C: D: I'm running a Windows 7 and it is installed on the C: drive. There is a jar file in D:\path\to\jar that I want to run. The problem, though, is that when I run the following command: java -jar D:\path\to\jar\myJar.jar I get an error from the program within myJAR.jar that some other jar file could not be found (let's call this jar file theirJar.jar). But in the MANIFEST file of myJar.jar, theirJar.jar is included in the class path. So what do I hate to do to make it work?
 01-03-2012, 06:13 PM PM User | #2 Fou-Lu God Emperor     Join Date: Sep 2002 Location: Saskatoon, Saskatchewan Posts: 16,606 Thanks: 4 Thanked 2,598 Times in 2,567 Posts What's the manifest for the classpath for the jar? Is it an absolute path (offhand I'm thinking that this *has* to be relative, but can't recall if the jar will build on an absolute)? It looks like it simply can't find it which would be the case if the classpath isn't absolute (which I'm thinking it can't be) and the actual CLASSPATH doesn't include the path to this linked jar. If it looks good, I'd try moving your jar to anywhere on C that is not the original location (if it existed), and is not in a system path and see if that goes. If that goes, its possible that this is a security issue across the volumes.
 01-03-2012, 07:22 PM PM User | #3 Apothem Regular Coder     Join Date: Mar 2008 Posts: 380 Thanks: 36 Thanked 25 Times in 25 Posts Yes the classpath for that jar is relative. It's weird, though. If I change to class path of the included jar to an absolute path to that included jar (D:\path\to\jar\theirJar.jar) it then get the error that a class from myJar.jar (the main class) cannot be found. If I don't place the absolute path, it is found but fails at running because theirJar.jar cannot be found. I currently want that jar in the D: drive. Plus I want to solve the error instead of doing something to avoid it. Last edited by Apothem; 01-03-2012 at 07:25 PM..
 01-03-2012, 09:00 PM PM User | #4 Fou-Lu God Emperor     Join Date: Sep 2002 Location: Saskatoon, Saskatchewan Posts: 16,606 Thanks: 4 Thanked 2,598 Times in 2,567 Posts Yeah, I kinda figured it had to be relative. I'm not suggesting that you don't fix it, but determine what the problem is first. Moving it to C somewhere and running it will verify whether it is a security issue or if it is a path issue. I'd suspect a path issue nonetheless now that you verified that the manifest has to be relative. So, there are two ways to fix this. First, you can add a bootstrap path to load the jar first using -Xbootclasspath/a:/path/to/ur/resource.jar, and the other is to move the external jar (what I would recommend). Grab your external jar and throw it in your jdk's lib\ext directory. Not sure where you'll find it, but it'll be along the lines of C:\Program Files\Java\jre6\lib\ext for example. Once there, that should run no problem with a manifest of just Class-Path: yourexternal.jar
 01-03-2012, 09:38 PM PM User | #5 Apothem Regular Coder     Join Date: Mar 2008 Posts: 380 Thanks: 36 Thanked 25 Times in 25 Posts In the C: drive, the problem persists. BUT both solutions do not seem to work; for the second solution I moved the resource jar into the ext folder but it still could not be found when I ran: java -jar D:\path\to\jar\myJar.jar And when I added the bootstrap path, it also gave the same error: java -Xbootclasspath/a:D:\path\to\jar\theirJar.jar -jar D:\path\to\jar\myJar.jar java -Xbootclasspath/a:"D:\path\to\jar\theirJar.jar" -jar D:\path\to\jar\myJar.jar
01-03-2012, 09:48 PM   PM User | #6
Fou-Lu
God Emperor

Join Date: Sep 2002
Posts: 16,606
Thanks: 4
Thanked 2,598 Times in 2,567 Posts
Quote:
 Originally Posted by Apothem In the C: drive, the problem persists. BUT both solutions do not seem to work; for the second solution I moved the resource jar into the ext folder but it still could not be found when I ran: java -jar D:\path\to\jar\myJar.jar And when I added the bootstrap path, it also gave the same error: java -Xbootclasspath/a:\path\to\jar\theirJar.jar -jar D:\path\to\jar\myJar.jar java -Xbootclasspath/a:"D:\path\to\jar\theirJar.jar" -jar D:\path\to\jar\myJar.jar
What is the manifest entry for Class-Path?

 01-03-2012, 10:26 PM PM User | #7 Apothem Regular Coder     Join Date: Mar 2008 Posts: 380 Thanks: 36 Thanked 25 Times in 25 Posts myJar.jar: Code: Class-Path: theirJar.jar Main-Class: path.to.MainClass theirJar.jar: none
 01-03-2012, 11:43 PM PM User | #8 Fou-Lu God Emperor     Join Date: Sep 2002 Location: Saskatoon, Saskatchewan Posts: 16,606 Thanks: 4 Thanked 2,598 Times in 2,567 Posts This should be right. The classpath with only the jar name should be usable from any known CLASSPATH location such as the lib\ext of the running version. Execute java.exe using the full path to the bin that shares the version with where you dropped the lib\ext. See if its your java.exe thats in Windows\system32 that's causing that issue. Edit: BTW, what is the actual stack trace you are getting? I assumed a classloader issue with the end result of a NoClassDefFound error.
 01-03-2012, 11:51 PM PM User | #9 Apothem Regular Coder     Join Date: Mar 2008 Posts: 380 Thanks: 36 Thanked 25 Times in 25 Posts Well, there isn't really a stack trace (as myJar.jar is really the producer's jar, and theirJar.jar is a library he includes). It just says that theirJar.jar could not be found. A solution I have found was to: D: cd path\to\jar java -jar myJar.jar But I don't know why this works and the other solutions do not.
 01-04-2012, 12:11 AM PM User | #10 Fou-Lu God Emperor     Join Date: Sep 2002 Location: Saskatoon, Saskatchewan Posts: 16,606 Thanks: 4 Thanked 2,598 Times in 2,567 Posts There should still be a stack trace though. Let me pull an example of a bad run off my test: Code: Exception in thread "main" java.lang.NoClassDefFoundError: gui/Frametest at test.main(test.java:10) Caused by: java.lang.ClassNotFoundException: gui.Frametest at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 1 more So this is what I get when I can't find the class Frametest. I ran this against a U: and pulled my Frametest.jar (name is irrelevant actually) from the C:\Program Files\Java\jre6\lib\ext directory. This is why I'm curious if you may have a different version of the java.exe in system32 (or, perhaps a version applied to the path itself?).
 01-04-2012, 12:56 AM PM User | #11 Apothem Regular Coder     Join Date: Mar 2008 Posts: 380 Thanks: 36 Thanked 25 Times in 25 Posts The error displayed didn't have a stack trace. I downloaded the source of the program and tried to locate the error. It seems to be something related to: if(! (new File("theirJar.jar")).canRead()) { - so I'm guessing File() is treating my "current" directory as the directory to work with, but it should really be working in the directory the jar belongs to. How would I do this?
 01-04-2012, 02:29 AM PM User | #12 Fou-Lu God Emperor     Join Date: Sep 2002 Location: Saskatoon, Saskatchewan Posts: 16,606 Thanks: 4 Thanked 2,598 Times in 2,567 Posts Oooohhhhh I see, so this isn't actually called via import commands, you are using something like the classloader itself. Is this your check (given the file name I'd suspect yes)? If it is, simply remove the check and use a try/catch instead. You don't care if the jar exists at all, you only care if the class itself is available whether it be through a jar or through a .class.

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 01:33 PM.