Jar questions and doubts
Hi,
I'm packaging my application into a jar, but I've got a few problems and doubts. My application is a desktop program with icons and images (under the img/ subdirectory), a set of configuration files (under the conf/ subdirectory) and a directory logs/ used by log4j to log activities. Now, having said that, what is the best way to make up a jar leaving outside only the logs/ directory (if possible)? I've tried to include the img/ and conf/ directory into the jar but they are not resolved when I launch the application.
Any suggestion is welcome.
Thanks,
Luca
From a command line, "jar tf yourjar.jar" will show the contents of the jar. You should see images/whatever.jpg, conf/whatever.txt, etc. If you don't see the files in the right directories, then you did not create the jar correctly.
If the files are in the jar but your app doesn't find them, then you have not properly coded the accessing of those files. You should have code that looks similar toURL url = getClass().getResource("/images/whatever.jpg");
//or
InputStream in = getClass().getResourceAsStream("/conf/whatever.txt");This may be helpful [http://java.sun.com/docs/books/tutorial/uiswing/components/icon.html#getresource] which is a part of the Swing tutorial. Also, that page has a link to [http://java.sun.com/javase/6/docs/technotes/guides/lang/resources.html]
Edited by: atmguy on Apr 7, 2009 10:57 AM
Similar Messages
-
Just starting a J2ME project.
An embarrassingly Noobie Question:
1) All the classes that are supposedly "built-in" to my device (phone)
do NOT need to be included in the deployed JAR file, right?
2) Anyone know how to do that in Netbeans 5.0?
Project -> Properties -> Build shows sources filtering
but that doesn't include anything from my "input"/library .JARS.
However, all the com.*, javax.* and java.* files are being included in
my output JAR file and it causes failures in preverify and loading
on the phone.
HELP!!hi,
any know this question
please send me the procedures about how load my J2ME
application(jad and jar file) into CDMA mobiles
like(Nokia 6255,6235,6235i etc..).
its very urgent for me,
please anybody known this answer reply very soon.
thanks a lot
laxmi.Hi
I am also having the same problem , any one has found solutions kindly inform. I want to install the spreadsheet viewer. Has any body developed solutions for the same - Please help
Thanks a lot
Ragupathi -
Creating & Using .jar files and manifests
I've read through hundreds of online tutorials on creating and using .jar's, but it's surprising how unhelpful they really are.
I've been trying to make a java program of mine standalone, so I can distribute it to others and allow them to run it without use of a compiler, etc (ideally just a .exe or .bat that they double click on). Everything I've found says I need to create a .jar of my program in order to do this. I was finally able to create a .jar but I got different errors relating to "main-class" and "manifest" issues...I tried running it with javaw.exe and had the same problem.
Some tutorials briefly discuss "meta manifest's", other's skip the concept all together in creating .jar's. I created a jar with:
jar cf A2.jar c:\jarTester.java
after changing my command prompt path to
C:\Program Files\Java\jdk1.6.0_01\bin
It created the .jar, but nothing worked. As above, it gave me errors relating to the "Main-Class" and "Manifest". So here's my question:
What involvement does a "manifest" play in .jar's, and how do I create/use one to create a .jar? Why is it necessary to specify the "Main-Class" when I have already done so in my .java file?
I believe that once I can get this "Main-Class" and "Manifest" problem straightened out, I will be able to create a batch file with the line:
java -jar A2.jar
is this correct? THANKS.I've read through hundreds of online tutorials on
creating and using .jar's, but it's surprising how
unhelpful they really are.really, hundreds?
I've been trying to make a java program of mine
standalone, so I can distribute it to others and
allow them to run it without use of a compiler, etc
(ideally just a .exe or .bat that they double click
on). Everything I've found says I need to create a
.jar of my program in order to do this. Make up your mind, do you want to make a jar or an exe?
I was
finally able to create a .jar but I got different
errors relating to "main-class" and "manifest"
issues...I tried running it with javaw.exe and had
the same problem.
Some tutorials briefly discuss "meta manifest's",
other's skip the concept all togetherthat's because the manifest isn't usually necessary
in creating
.jar's. I created a jar with:
jar cf A2.jar c:\jarTester.javaugh, that won't work. you need to put the class file in there, not the source. or you can put the source in as well if you want, but the class is necessary
i'm ignoring the rest of this post for now
go back to Google and type in jar manifest and read more -
Here are some common WTC questions and answers:
Q1: What is the transaction story for WTC between WLS and Tuxedo and how
does it differ from Jolt?
A1: In version 1.0 of WTC transactions may be started in WLS and will
"infect" Tuxedo with the same transaction. That implies that there is one
and only one commit coordinator, and that is in WLS. In version 1.0 of WTC
transactions originating
in Tuxedo via WTC is not supported. In version 1.1 of WTC transactions from
Tuxedo into WLS via WTC can be used, but only in Beta mode, as we will not
have done the required QA of "inbound" transactions. In order to use
inbound transactions in WTC 1.1 you will need to turn on the use of beta
features with an attribute called "UseBetaFeatures" on the WTC Startup class
in WLS.
This differs from Jolt in that while Jolt can start transactions in Tuxedo,
these transactions are not coordinated with anything in WLS. Hence it is
impossible to do a 2 phase commit which involves WLS resources and Tuxedo
resources with Jolt. Since Jolt does not have any means of invoking WLS
services transactions in that direction do not make sense.
Q2. How does the security mapping work?
A2: WLS and Tuxedo can share the same set of users (though they may be
administered differently in the two systems) and the users can propagate
their credentials from one system to the other. For example, if John Wells
logs into WLS then the services which he invokes in Tuxedo will have all of
the ACL permissions of John Wells as defined on the Tuxedo side.
Furthermore, if Jolene User logs into Tuxedo then any resources she attempts
to access in WLS via WTC will be checked against Jolene User's rights in WLS
land.
In order to accomplish this, a few things need to be set up:
1. You must be using Tuxedo 7.1 or Tuxedo 8.0 for this to work. Tuxedo 6.5
did not have the security infrastructure necessary to make this happen.
2. In your BDMCONFIG on the Tuxedo side you will need to set ACL_POLICY and
CREDENTIAL_POLICY to "GLOBAL" for the WLS remote domain. ACL_POLICY
controls whether or not a domain accepts credentials coming from a remote
domain and CREDENTIAL_POLICY controls whether or not we send credentials to
a remote domain. (In Tuxedo 7.1 there was no CREDENTIAL_POLICY - we always
sent the credentials to the remote domain).
3. In your BDMCONFIG on the WLS side you must likewise specify <ACL_POLICY>
and <CREDENTIAL_POLICY> to be "GLOBAL."
4. On the WLS side you must also configure a <TpUsrFile> which will point
to a file of the exact same format as the tpusr file generated by the
various Tuxedo commands to add and delete users. (Which also happens to be
of the same format as the unix /etc/passwd file). WTC needs this file
because in WLS users do not have user identification numbers or group
identification numbers. Hence we need a way to map WLS users into the
standard Tuxedo UID/GID appkey.
Voila! You have now set up your system such that users logged into either
system can be given access privelidges in the other system. This is known
as single sign-on. We are currently working on a way to better integrate
the two user databases between WLS and Tuxedo, and one day we will have
single administration and single-sign on!
Q3: How is the performance of WTC?
A3: Obviously, results will vary based on your machine, CPU, application
(i.e., transactions/no transactions) etc...
However, in the performance lab here we have seen WTC perform at levels that
nearly equal Tuxedo in a similar configuration. The performance is equal to
or better than Jolt, and will scale much better than Jolt because of the
concentration of network bandwidth.
Q4: What fail-over/fail-back mechanisms are there in WTC?
A4: WTC has many of the same fail-over fail-back mechanisms which /T
domains had. Any service can be offered by multiple remote domains, and if
a domain link is down we will attempt all of the backup domains. In /T
domains there was a limit of three backup remote domains, but in WTC there
is no limit to the number of backup domains you can configure for a service.
Furthermore, we support the connection policies of ON_STARTUP, ON_DEMAND and
INCOMING_ONLY. If the policy is ON_STARTUP then you can also configure a
retry interval and max-retries. We will attempt to connect to ON_STARTUP
remote domains every retry interval for a maximum number of retries before
giving up. If a domain is configured as ON_STARTUP or INCOMING_ONLY and the
connection is not currently established then no services will be routed to
that remote domain.
Q5: What support features are available in WTC?
A5: WTC has a tracing feature which can be enabled dynamically. If a
customer reports a problem, support will likely ask the customer to turn
tracing on and send a log file. This tracing facility has several levels of
severity and can also help debug WTC applications. It is turned on by
setting TraceLevel in the WTC startup class. The following are the defined
levels:
10000 - TBRIDGE Input/Output
15000 - TBRIDGE extra information
20000 - Gateway Input/Output (this will trace the ATMI verbs)
25000 - Gateway extra information
50000 - JATMI Input/Output (this will trace the low-level jatmi calls)
55000 - JATMI extra information
60000 - CORBA Input/Output (this will trace CORBA calls)
65000 - CORBA extra information
Q6: Will Jolt be deprecated?
A6: No. There are some features of Jolt that are not covered by WTC. For
example, the Jolt registry API are not supported by WTC. Furthermore WTC
must run in conjunction with WLS, while Jolt can be run from Applets or from
free-standing Java applications.
Q7: What about JCA? Is WTC a JCA adapter?
A7: WTC is not a JCA adapter. JCA does not define semantics for inbound
invokations into the JCA container, but WTC allows for Tuxedo clients to
invoke WLS EJBs. However, the jATMI object interactions are based on the
JCA client model. BEA is currently evaluating several JCA strategies for
connections into Tuxedo.
John Wells (Aziz)
[email protected]
[email protected]Q8. What versions of Tuxedo are supported?
A8. WTC 1.0 will support Tuxedo 6.5 and Tuxedo 8.0. WTC 1.1 (which adds
CORBA support) will support Tuxedo 6.5 and Tuxedo 8.0. Soon after the
release of both of these products we will certify WTC with Tuxedo 7.1.
However, the version of Tuxedo 7.1 you will need to have will be Tuxedo 7.1
after a certain patch level, which I don't know the number of yet. I will
attempt to keep the public informed about which patch level will be required
in Tuxedo 7.1
Q9. What WLS Releases will be supported?
A9. WTC 1.0 will be certified on WLS 6.0 SP2, WTC 1.1 will be bundled with
WLS SilverSword release (6.1?)
Q10. How will WTC be packaged?
A10. WTC 1.0 will be a separately downloaded binary (one for unix, one for
NT) that the user will have to install and configure in his/her WLS
environment. (Configuration will consist of putting the jatmi.jar file into
the classpath (as well as the normal BDMCONFIG configuration, of course)).
WTC 1.1 will be bundled right in there with the WLS SilverSword release.
Q11. When will WTC go live (no more beta)?
A11. This is a question for Jeff Cutler, but my impression is that WTC 1.0
will be shipped in the same time-frame as the Tuxedo 8.0 release and
obviously (see A10) WTC 1.1 will be shipped with WLS SilverSword.
John Wells (Aziz)
[email protected] -
Hello,
I hate to ask such a simple question, but I'd like to get confirmation from people who know.
It is possible to package non-EJBs into a deployed JAR containing EJBs, isn't it? I have heard that you cannot mix a non-EJB class into a JAR that contains EJBs, but my interpretation of the literature I've found about packaging EJBs seems to indicate otherwise.
Basically, it looks like you would want to (or need to in some cases) package any class that an EJB depends upon through inheritance or through another association (e.g. a custom user Exception class that and EJB might throw) into the same JAR file.
Please reply and set me straight on this. Thanks in advance.
Jeff1. You can include any classes in your EJB jar file, and it is widely used. You can also include other files (e.g. properties) and access them through the class loader (as resources).
2. If you use some libraries, you may reference them with Class-Path: element in your manifest file. It is not necessary to unpack the library and include its classes in your jar file. (About "Class-Path" -- look page about manifest in the java tutorial (in the JAR files trail)).
3. Your JAR can contain no classes, just a deployment descriptor, if your classes are somewhere and you have referenced them with "Class-Path". ;) -
My applet class is using other classes in my package,
So do i need to create a jar file and specify that jar file in <applet archieve = :myjar.jar"
I did created the jar file , but its not loading up, the browser just says Loading java applet, what might be the reason, does it depends on size of jar file?
or my tags are wrong.
my applet tag is
<html>
<applet archive = "myjar.jar"
code = "front.class"
width.. >
the front.class file is also in myjar.jar.
Any help....
Also one more question,
Can i call other applets within one applet class.
I have a gui, when a particular button is clicked on applet
i want to go to other applet, so how should i call it in that buttons action listner?
And in my applet class i am using one other class from my package which actually coonects to databse through JDBC. now say i have a button on my applet whihc says "Connect", and when that button is clicked then I created object of my other class which makes connection
through databse. So will this work from applet?
Thanksmy applet tag is
<html>
<applet archive = "myjar.jar"
code = "front.class"
width.. >Just to get you started - if it is a JApplet, not an Applet, then you need to use different HTML tags, otherwise it won't work. If you have JDK1.3, look in the /bin directory - you should see a file called "HTMLConverter.bat" if it's there, cd to the directory where your HTML file is, and type
"HTMLConverter wateverYourHTMLPageIsCalled.htm"
(case sensitive - and remember to check whether its called ".htm" or ".html")
When it has executed successfully, look at the source of your html - it should be different (<OBJECT> tags and lots of other stuff)
If you have an older version of the JDK, or don't have HTMLConverter.bat, you can download it from Sun's website.
Now you should be able to run your applet...
>
Can i call other applets within one applet class.
If you use "getAppletContext().showDocument(URL url)", this will replace the current html page with the new one - is that what you mean?
And in my applet class i am using one other class from my package which actually
coonects to databse through JDBC. now say i have a button on my applet
whihc says "Connect", and when that button is clicked then I created object
of my other class which makes connectionthrough databse.
So will this work from applet?Should do :-) -
My applet class is using other classes in my package,
So do i need to create a jar file and specify that jar file in <applet archieve = :myjar.jar"
I did created the jar file , but its not loading up, the browser just says Loading java applet, what might be the reason, does it depends on size of jar file?
or my tags are wrong.
my applet tag is
<html>
<applet archive = "myjar.jar"
code = "front.class"
width.. >
the front.class file is also in myjar.jar.
Any help....
Also one more question,
Can i call other applets within one applet class.
I have a gui, when a particular button is clicked on applet
i want to go to other applet, so how should i call it in that buttons action listner?
And in my applet class i am using one other class from my package which actually coonects to databse through JDBC. now say i have a button on my applet whihc says "Connect", and when that button is clicked then I created object of my other class which makes connection
through databse. So will this work from applet?
ThanksYou didn't show all of your applet tag, but it should look like this:
<HTML>
<APPLET CODE = front.class, ARCHIVE = myjar.jar, width = ???, height = ???>
</APPLET>
</HTML>
Assuming your applet is not crashing, this should load it. I recommend using the appletviewer tool in the JDK, it provides more detailed error messages. I hope this works for you.
Now inter-applet communication. This is forbidden, sorry. However, if you really want to get fancy; remember that all applets can communicate back to the host from which they came. So if you want to build a small server on your host machine which all your applets log into, they can then communicate with each other through the server. -
Executable jar files and manifest file
Hi,
I have the following files in a folder named: Test
a.jar
b.jar
c.jar
Driver.class
Driver.mf
Here, MainClass is the main executable class that uses a,band c.jar files. This is how my MainClass.mf file looks:
Manifest-Version: 1.0
Main-Class: Driver
Class-Path: a.jar b.jar c.jar
Now I use the following command to make one executable jar file:
jar cmf Driver.mf DriverMain.jar *
It creates an executable jar file named : DriverMain.jar
Now I copy the executable jar file (DriverMain.jar) into a different folder named: RunTest
and double click it, doesn't work.
my question is:
what am I doing wrong? Any special characters needed in my Driver.mf file (space/newline/etc)?
What I am trying to get is: One execuatble jar file so I can just double click to run it, and that single executable jar file will have all the necessary jars in it (i.e. a.jar, b.jar, c.jar in this case)
Anyone please help!
Thanks
-RonRony,
Sorry to disappoint, but you can not use embeded jar/zip files within an executable jar. The JDK sadly for some reason decided this was not a useful idea, so developers like me who want to distribute plugins with thier own dependencies have one of two choices. You either have to unzip the jar file that contains the embeded jars to a directory, then run your primary exectuable jar, OR you have to write a custom classloader that your "launcher" creates then loads the embeded jar files.
The best thing to do is either jar up a, b, c and driver into one jar, so that it works, if you can legally do this. A lot of 3rd party libraries may not allow this per their license. Otherwise, another choice is to use a free installer or buy an installer that allows you to distribute a single exectuable installer program that will properly create the dir structure you need.
As for the way it works, if you declare:
Class-Path: a.jar b.jar c.jar
the JAR loader code in the JDK looks in the root dir where your application was started for a/b/c jar files. They have to be on disk.
If you want to place them in /lib, for example, you would havd a jar file like:
Driver.class
Driver.mf
lib/a.jar
lib/b.jar
lib/c.jar
When unzipped, your "root" dir would look exactly like the above, and your manifest would have Class-Path using ./lib/a.jar ./lib/b.jar ./lib/c.jar
Anyway, there thus far isn't any way around this issue of embeding jar files in an executable jar file. You MIGHT be able to not specify any classpath, then in your Driver.class, create a new custom classloader that dervies from URLClassLoader, but in the findClass(), you get a ref to the .jar file that the classloader class is inside of, and from that use it to find the lib/*.jar files and add them to the classpath. For this to work, however, your Driver.class code should ALSO be contained in an embeded jar file that is loaded by this custom loader. The only thing Driver.class would contain (and I would rename it to something like Launcher) is the code to create the custom classloader.
It's fun stuff, but a little bit of work to make it work. You can infact make it work! I may yet one day take our plugin engine custom loader and create a way for this to work! -
Jar file and source code? (new to java!)
Hi all!
Sorry if this is a dumb question but I'm really new to java (.net guy).
Someone sent me a jar file and now I need access to source code. I now that I can rename to .zip and view its contents (.class)...
But what about source code? Can I decompile? As i understand, .class files are compiled .java files...
Should I ask for the source code to the guys that sent me the .jar file?
thanks
jayHumm... is java as fast as replies in this forum? Thank's for your replies warnerja and zadok
I need the source code so that I can understand how the original developer solved a problem. I can ask for the source code.
I posted this message because I was afraid that the question was stupid and source code was in front of me. I am really new to java!
So. No source code in .jar or .class files. Right?
Thanks
Jay -
i have really really tried to answer this question.
i searched the forums. i read the api.
so please, haha, please help.
i know jar questions dont typically get a warm reception.
I have a folder containing a couple folders and one jar file.
Images/
Data/
MyApp.jar
i cannot access the images in the Images folder.
im getting this error:
Resource not found: /Images/ToolBar/pic.gif
Uncaught error fetching image:
java.lang.NullPointerException
at sun.awt.image.URLImageSource.getConnection(URLImageSou
9)
at sun.awt.image.URLImageSource.getDecoder(URLImageSource
at sun.awt.image.InputStreamImageSource.doFetch(InputStre
rce.java:248)
at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java
at sun.awt.image.ImageFetcher.run(ImageFetcher.java:136)
this is the code i use to load images:
String imgLocation = "Images/ToolBar/" + imageName + ".gif";
URL imageURL = MyClass.class.getResource(imgLocation);i also tried it with a "/" before "Images" in the code.
I tried adding the folder to the manifests classpath.
I also tried knocking on wood and counting sheep.the way my computer is configured i never use "-cp . " when
running a java program.
it usually uses the present directory as the class path.
but i have looked into that (maybe im doing it wrong).
im running "java -jar MyApp.jar" from the command-line (in XP)
from the directory that holds the .jar and the Images/ folder.
i tried "java -cp . -jar..."
i also tried putting the class path in the manifest file but every\ytime
i did that i got "no class in main" error.
if C:\My\Program contains MyApp.jar and directory Images/
Class-Path: C:\My\Program\Images
didnt work
Class-Path: C:\My\Program ; C:\My\Program\Images
didnt work
i tried the / both directions
ive tried countless permutations of this.getclassloader / getclass blah blah also.
every thread gives the class loader as the answer but so far
nothing has worked.
its amazing how many times this question has been asked and
there usually isnt an answer.
im depressed, haha. -
Where can I buy a larger hard drive for my late 2008, 15" macbook pro? From reviewing questions and answers on the support community it would appear that having Apple remove the old and install the new hard drive is recommended. But how/where?
Welcome to Apple Support Communities
You can install the new hard disk yourself if you want to. You just need a 2'5" SATA II hard drive, which is compatible with your MacBook Pro. You can buy one at OWC > http://eshop.macsales.com/shop/hard-drives/2.5-Notebook/ You can filter hard drives by computer, so press a "Click to view all...", choose your computer in the sidebar and it will give you the compatible hard drives.
There are different brands for the MacBook Pro. The most recommended are HGST and Seagate, which have good reputation. A 7200 rpm hard drive will give you extra performance -
I have no "Rescue email" contact in order to reset my security questions!! I've been trying now for 4 days to contact Apple/Itunes but I only get sent answers from a support team that say they cannot help me with my problem!!
The thing is that I can't ever remember answering any security questions and without a rescue email, I'm unable to reset them or even set them for the first time!!
I can't believe that no-one from Apple/Itunes can help me with this simple problem but unfortunately that is the case - Incredible, isn't it!!!
Would anyone know how I could solve this problem online??? Because each time I sign into Itunes, the same security questions reappear and reappear and reappear. In fact I've got to the point where I feel like uninstalling Itunes and downloading an alternative.
Many thanksYou need to ask Apple to reset your security questions; this can be done by clicking here and picking a method, or if your country isn't listed, filling out and submitting this form.
They wouldn't be security questions if they could be bypassed without Apple verifying your identity.
(111154) -
I am trying to download music onto my phone and it is saying I need to answer sercurity questions and the questions they are asking I have never answered before therefore I don't know the answers and so when I put the answers I think it is they are wrong I don't know how to fix this I answered the questions twice and so I need help to answer them as I don't want to lock my phone please help me
Not Possible...
Contact iTunes Customer Service and request assistance
Use this Link > Apple Support iTunes Store Contact
Good Luck. -
Please can someone help me
From a Kappy post
The Three Best Alternatives for Security Questions and Rescue Mail
Try # 2
1. Use Apple's Express Lane.
Go to https://expresslane.apple.com ; click 'See all products and services' at the
bottom of the page. In the next page click 'More Products and Services, then
'Apple ID'. In the next page select 'Other Apple ID Topics' then 'Forgotten Apple
ID security questions' and click 'Continue'. Please be patient waiting for the return
phone call. It will come in time depending on how heavily the servers are being hit.
2. Call Apple Support in your country: Customer Service: Contact Apple support.
3. Rescue email address and how to reset Apple ID security questions.
A substitute for using the security questions is to use 2-step verification:
Two-step verification FAQ Get answers to frequently asked questions about two-step verification for Apple ID. -
i am trying to use my account to purchase but i forget my security questions and also i gave the wrong email address. What can i do?
Apple ID security issues -
Call Apple Care and ask for the Account Security Team. They can assist you with your issue.
Maybe you are looking for
-
IMac crackling and shutting down intermittently
Can anybody help? Please be patient. :-/ I've seen a few similar issues but not exactly the same and none recent. Apologies if there's a similar recent thread that I haven't seen. I have a mid 2010 21.5inch iMac 3.06Ghz i3 with 12 GB RAM (upgraded fr
-
I am aware that the apps 11.5.7 are distributed with 9iAS 1.0.2.2 and that Discoverer 9.0.2 works with 9iAS Release2. If I install a second 9iAS to connect to the same Apps Database, will that conflict? After that, if I create an EUL version 5 over t
-
Hi, We have installed content server and it is working fine. We would like to install cache server to access content server from different location to reduce the access time. Is there any document/guide to link cache server to the existing content
-
BPE adapter : message not used by any process
hi frnds, I've created 2 scenarios using BPM 1) merge scenario: 2 msgs ==> BPM ==> 1 msg 1st msg is going without any problem. but 2nd msg is giving error saying 'BPE ADAPTER ERROR: message not used by any process'. i checked in sxi_cache and found t
-
My iMac disappears from my network sometimes
I'm not sure what's happened but as of lately I've noticed that my iMac(late 2009) disappears from the network every now and then. What can I do to correct this? Thanks in advance