Results 1 to 20 of 27
Thread: Where to place the jar files..?
- 03-25-2010, 09:01 PM #1
Where to place the jar files..?
I made a program in netbeans that uses a jar file.. that i imported to the libraries in order to make it run... thats ok. the program is running correctly.
Now i want to run this very program on another computer where netbeans is not installed.. or say i need to run this program on multiple computers and in that case it would be practically infeasible to install netbeans on every computer just for making this program run..
I mean ..... i am running the file on the target system and it is obviously unable to recognize the functions that i have used from the "jar " file... where should i place the jar file on the target system or set class paths what ever ..in order to make the program run correctly.; plz suggest. thnx.:confused:The Quieter you become the more you are able to hear !
- 03-25-2010, 09:51 PM #2
Senior Member
- Join Date
- Mar 2010
- Posts
- 266
- Rep Power
- 4
Doesn't matter where you put the jar file as long as it's in the classpath.
For example, you have two jars, one with your program, one you depend on. Your directory structure looks like this:
and you want myprogram.bat to execute your program. So it can look like this:Java Code:/myprogram myprogram.bat myprogram.jar lib/ needed.jar
hope that helpsJava Code:java -cp ./myprogram.jar:./lib/needed.jar com.myself.MyCoolProgram
- 03-26-2010, 02:44 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
It's nothing to do with NetBeans. You said that you've added additional JAR files into your project and it's working fine. Cool. Then what you've to do is, build the project. Right click on the project and from the pop-up menu click on build. You comes with message on output window, notifying that the process is successful or fail. If successful it gives you a folder path to the build package. Actually it's in your project folder, check for a folder name dist there. That's the only folder you want. Since you've used additional JAR files in that folder you can see a folder name lib as well as a JAR file with the name of your project.
If you want to run your application in another PC, you have to bring that complete dist folder there. That's all. But keep in mind you have to set the CLASSPATH in that new PC, either manually or by programatically.
- 03-26-2010, 07:01 AM #4
1.
suppose we forget about the package and all. now i have a single class file, say, "first.class"Doesn't matter where you put the jar file as long as it's in the classpath.
and i have a jar file, say, "jest.jar" .....
I kept the jar file in the drive "E:\jest.jar" and the class file in the directory "D:\first.class" or in the same directory... next i set the class path --- "E:\jest.jar" manually.. Now when i run the class file it is never executed?? why?
2. Also i need to run the file "first.class" inside the jar package say "fun.jar".... how can i run the file "first.class" from inside the jar file at the command prompt.? Also to make note of is that this jar file contains multiple class files that are independent programs.. so i have not set any class as the main class of the jar file..! plz suggest. i need to run these programs individually...
3.Now i am a bit of confused.. since my setting classpaths isn't working.. so what classpath should i exactly set manually and how can i set the classpath programmatically.plz explain.But keep in mind you have to set the CLASSPATH in that new PC, either manually or by programatically.The Quieter you become the more you are able to hear !
- 03-26-2010, 07:07 AM #5
what commands the batch file is supposed to hold?myprogram.batThe Quieter you become the more you are able to hear !
- 03-26-2010, 07:57 AM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Suppose your main.jar is stored in directory X and another jar file support.jar is stored in directoty X/Y (i.e. you only know the path to Y relative to X); you can put a line in the manifest of main.jar like this:
All the installer of all your code has to do is install main.jar in X and support.jar in X/Y and you're in business. You don't need .bat files at all, your manifest can handle it.Java Code:Class-Path: Y/support.jar
kind regards,
Jos
- 03-26-2010, 09:47 AM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Exactly.
And Netbeans does all that for you, as Eranga says.
There's no need to faff with Classpaths either, since the Manifest tells Java where to find its dependencies.
- 03-26-2010, 10:05 AM #8
I am still not answered! sori
suppose we forget about the package and all.
Also to make note of is that this jar file contains multiple class files that are independent programs.. so i have not set any class as the main class of the jar file..! plz suggest. i need to run these programs individually...
using cmd !The Quieter you become the more you are able to hear !
- 03-26-2010, 11:30 AM #9
I think I can explain my problem more clearly !!:D
First forget about netbeans and all..........
Suppose you make a java file from the notepad that import a package say--
javax.swing.* . you as all would be knowing that this package is packed into a jar file called rt.jar that is locate in C:\Program Files\Java\jdk1.6.0_14\jre\lib at least in my computer.. now when we compile this program from the command prompt as javac x.java or interpret it as java x this program is executed . definitely surely.
Now consider a scenario......... apart from using the rt.jar i.e, packages inside this jar file i am using another jar file named click-0.18.jar from which i am using the package org.apache.commons.io.FileUtils exactly like we use the traditional class inside the java packages....i think i am clear uptil now and if not let me know...
now i am telling what exactly i attempted .ok.
1. I.... tried to compile the program without setting any classpath ... perhaps if needed. Obviously it isn't going to work. thats f9
2. Now I set the classpath as say -D:\ where the supporting jar file is kept... i again tried to compile the program.. it didn't worked again.
3. Next i copied this supporting jar file in the very directory--C:\Program Files\Java\jdk1.6.0_14\jre\lib that keeps the obviously rt.jar and then again tried to compile the program.. and i failed again ...
How the heck can i compile my program...plz suggest.
Also if you are still not clear with what i meant in above please do ask. I need help desperatly..thnx:)The Quieter you become the more you are able to hear !
- 03-26-2010, 12:28 PM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
See the first reply to your post by iluxa.
you need to use the -cp switch, and then list the required jars (and where they are in relation to where you're running this)...if there are several jars then you can stick them in a file and refer to that file instead. But you still need the -cp switch (and don't forget the "." in the list of locations).
See here.
ETA: Don't simply stick the jars in the JRE lib. That's Bad Practice.
- 03-26-2010, 12:35 PM #11
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Yeah, without setting up the classpath you cannot compile any Java class. If you are using an IDE, then no need to worry about that. Because IDE will care of that. If you are looking to do that on Notepad then yes, you have to set it in environment variables.
Can you explain a bit more about how you set the CLASSPATH?
You have to set the class path to bin folder. I'm confusing how you set the CLASSPATH. So as I said earlier can you explain a bit more about the CLASSPATH setting
- 03-26-2010, 01:04 PM #12
In the case when i placed the click-0.18.jar file in the directory C:\Program Files\Java\jdk1.6.0_14\jre\lib and tried to compile my program from inside the C:\Program Files\Java\jdk1.6.0_14\bin directory.. i think in that case i don't need to set any class paths.. as traditionally
My question is when my program is using the rt.jar without seeking my concerns then in the case when i placed the click-0.18.jar in the above specified directory where the rt.jar file is also placed then why didn't the program compile as traditionally.. or how can i make the file compile.?
I don't have very good idea of setting classpaths but i m looking for if you people can help me ... in doing so if required.
Then where should i place it exactly..ETA: Don't simply stick the jars in the JRE lib. That's Bad Practice.
Isolating my need exactly.. i have made a simple java file that uses a supporting jar file.. now where should i place this jar file or perhaps whatever .. i don't know in order to make my program run...
plz suggest.The Quieter you become the more you are able to hear !
- 03-26-2010, 01:31 PM #13
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
You have a project...whether that is a sinlge java class or not is irrelevant. A project has a directory structure with a folder for source (based on packaging) and a folder for dependencies (usually called lib).
You then use javac to compile, with a -cp flag to reference the lib directory.
To run this you use java with a -cp flag as mentioned above (listing the jars).
This way each project maintains its own jars, since each project might require different versions of jars.
- 03-26-2010, 01:59 PM #14
Also I made a note in one of my earlier posts that i have not set the main class of the jar file... because it contains multiple independent programs that are required to be executed independently ...... so what would be my command on cmd such that i am able to run a file say Cd00.java that is packaged inside the jar file :confused:
The Quieter you become the more you are able to hear !
- 03-26-2010, 02:04 PM #15
I type this command---
C:\Users\Mild Seven\Desktop\OtherOther\JSection\COMPIL~1>javac -cp "E:\Inventory
\Compiler Design\dist\lib" Cd00.java
What error I get exactly is---
Cd00.java:11: package org.apache.commons.io does not exist
import org.apache.commons.io.FileUtils;
^
Cd00.java:21: cannot find symbol
symbol : variable FileUtils
location: class Cd00
String str = FileUtils.readFileToString(chooser.getSelectedFile (), "UTF-
8");
^
Cd00.java:71: cannot find symbol
symbol : variable FileUtils
location: class Cd00
FileUtils.writeStringToFile(chooser.getSelectedFil e(), output_str, "UTF-
8");
^
3 errorsThe Quieter you become the more you are able to hear !
- 03-26-2010, 02:07 PM #16
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Have you read the documentation?
Just asking, because all this is in there.
I've already posted a link to the stuff for "java" command, but here's the page for javac.
When using -cp for a directory containing jar files you need a * at the end.
- 03-26-2010, 02:18 PM #17
When using -cp for a directory containing jar files you need a * at the end.
i don't find exaclty what you are saying ....in the link you specified
I tried this..............
C:\Users\Mild Seven\Desktop\OtherOther\JSection\COMPIL~1>javac -cp "E:\Inventory\Compiler Design\dist\lib\*.jar" Cd00.ja
Iam i now correct??if i am then it isn't working.......
Can you please tell me what would exaclty be the command.The Quieter you become the more you are able to hear !
- 03-26-2010, 02:25 PM #18
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Did you read my link to javac?
I'll quote, since clearly your mouse isn't working or something.
*...not *.jarFor example, if directory foo contains a.jar and b.JAR, then the class path element foo/* is expanded to A.jar;b.JAR, except that the order of jar files is unspecified. All jar files in the specified directory, even hidden ones, are included in the list. A classpath entry consisting simply of * expands to a list of all the jar files in the current directory.
- 03-26-2010, 02:41 PM #19
I worked! I am sorry i was actually looking for the command and overlooked the statements.....
C:\Users\Mild Seven\Desktop\OtherOther\JSection\COMPIL~1>javac -cp "./*" Cd00.java
But the following error is shown when i try to interpret the command.. even when the directory contains the compiled version of this program....
C:\Users\Mild Seven\Desktop\OtherOther\JSection\COMPIL~1>java -cp "./*" Cd00
Exception in thread "main" java.lang.NoClassDefFoundError: //Cd00/java
plz suggest!The Quieter you become the more you are able to hear !
- 03-26-2010, 02:50 PM #20
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
If the jars are in the same directory you're in (which I presume by the "./*") I think you can simply use * in the javac command.
For the java command, you'll also need to specify "." as well. The "./*" simply tells java to get all the jar files from where you are, but in doing that it assumes that's the only places it needs to look to run things. So it's looking for your class (I think, been a bit) in those jars.
So you need .;*...or something to that effect. Don't need quotes around them either.
Similar Threads
-
Edit In place for JSF
By akira_mz86@yahoo.com in forum New To JavaReplies: 2Last Post: 02-24-2010, 10:35 AM -
Where to place jar files
By rummy in forum New To JavaReplies: 3Last Post: 02-11-2010, 01:08 AM -
Extract jar and place in other folder
By kkk in forum Advanced JavaReplies: 4Last Post: 08-31-2009, 09:42 AM -
How To Place Three Files In A Folder
By ramesh.8189 in forum AWT / SwingReplies: 4Last Post: 02-12-2009, 07:59 AM -
how to place the controls >
By makpandian in forum AWT / SwingReplies: 1Last Post: 12-18-2008, 06:17 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks