| Play audio clip in an Application |
|
 |
Index ‹ java-programmer
|
- Previous
- 2
- want to sort tables inside a complex mechanism, what can be the approach?I have a situation where first we are fecthing some ids(list of say
version ids using hibernate form database)
then keeping those list of data in a Pager Object(Paging mechanism
displays 100 rows per page out of complete sa 100 or so.)
This pager class does two things one takes whole list of ids
(Collection of version_id).
(Every time based on search criteria it changes. For searching in
hibernate values are hardcoded. Want modification with minimal changes
as many things are interrelated here.)
and other thing it checks no. of contents based on that displays data
per page(100 here).
It means stores all data from database and send it oage by page.(First
thing to notice)
Next all this is getting stored in Report page where it searches other
column names based on ids(version_id) the other column names are
getting changed for different requests so what we do is take all other
columns collectAllExtraFields(this is also getting changed everytime
based on what is getting searched.)
Now all this is getting accumulated while displaying but as we know
what to display we hardcoded all fields required to display based on
search. But all fields are searched based on the id fetched from
database first time which Pages is storing.
like this
Search for product user information & retrun results in the form of a
paged table for components used by specific product
ComponentVersion versionObj =
versionHandler.getComponentVersion(versionId);
String CAUsers = ctHelp.getCAUsersSection(versionId);
tableBody = tableBody + ((i%2 == 0) ? "<tr
class='table_banded_row' valign='top'>" : "<tr class='table_row'
valign='top'>");
tableBody = tableBody + "<td class='table_data'>" +
procHelper.getCompVersionLink(versionId,
versionObj.getCompName(), versionObj.getCompVersion()) + "</td>";
tableBody = tableBody + "<td class='table_data'>" +
CAUsers + "</td>";
tableBody = tableBody + "<td class='table_data'><span
class='data'>" +
versionObj.getComponent().getType() + "</span></td>";
tableBody = tableBody + "<td class='table_data'><span
class='data'>" +
versionObj.getComponent().getVendor() + "</span></td>";
tableBody = tableBody + "<td class='table_data'><span
class='data'>" +
versionObj.getRecommendationType() + "</span></td>";
tableBody = tableBody + "</tr>";
/** Get ComponentVersion ID with hyperlink to ComponentVersion Detail
page
*/
public String getCompVersionLink(long versionId, String compName,
String compVersion){
return "<a class='datalink' title='" +
this.getComponentFlyOverText(versionId) + "'
href='/techstacks-v2_1/content/components/componentDetail.jsp?versionId="
+ versionId + "'>" + compName + " " + compVersion + "</a>";
}
this is getting called by Report.jsp to display.
As this is getting changed everytime its called form classes not used
in jsp directly i think.
Now original objective is to sort all these displayed columns.
If user clicks on any of the column name everything sholud get sorted
on that basis.but sholud not call databse for same again by using same
id and mapping with any new column name this sholud be done. Paging
mechinasm to be used as it is if possible without major changes.
i don't know where to start with as started looking on this code just
2-3 days back only.
Vj
- 4
- Send ARPHello everyone,
I want to verify if an IP is in my local net or not.
If I send an ARP request and get a MAC from that then the IP is in the
local net.
That's why I need to send an ARP request in Java under Windows XP and
NT.
Can anyone tell my how this is done?
Doing this native with the Windows iphlpapi.dll seems to be a bit
complex.
Any ideas for any easy way?
Thanks.
bye bembi
- 4
- What will be your DAO design ?For the following tables, which is a general rdbms design, what classes will
you create for accessing these tables ?
Table 1 : Group
group_id (PK)
group_desc
Table 2 : User
user_id (PK)
user_name
Table 3 : Group_User
group_id (FK)
user_id (FK)
- 6
- History of objects?Hi
a relatively complex project I am working on now has a need for
"versioning". I mean, we have a system for administration of data (creating
and updating) in a database, and this data needs to be saved as separate
versions each time it is updated - a lot like a CVS.
The data is in the main "bridges", which have lots of data (name, location,
height etc), and lots of related data: persons (controller, supervisor);
tasks to be performed...
It should for example be possible for a user to view a "bridge" as it looked
on a certain date in the past, with all its related data (as they also were
at that date).
Does anyone have some good ideas about how we can save a history of versions
of all our objects? Where can I start to look for good ideas? Could we use
CVS via some sort of java api?
Thanks,
Peter
- 6
- Making a soundcard objectI have this idea of making a modem, that requires the soundcard to act
as my A/D and D/A, and in the middle will be my attempts at DSP. I
came up with this object, and it seems to test OK, but I could use
some constructive criticism, as I am definately at the OO 101 stage.
Merry Christmas, and a Happy New Years soon!
/**
* SoundCard.java
*
* @version 1.0, 1 December 2007
* @author Steve Sampson, K5OKC
*
* Public Domain (p) December 2007
*/
package modem;
import javax.sound.sampled.*;
import java.io.*;
public class SoundCard {
private static AudioFormat format;
private static TargetDataLine targetLine;
private static SourceDataLine sourceLine;
private static AudioInputStream sound;
public void SoundCard() {
}
/*
* Initialize Sound Card
*/
public boolean initPCM(double dblSampleRate) {
/*
* Encoding,
* Sample Rate (float),
* Sample Size (In Bits),
* Channels,
* Frame Size,
* Frame Rate (float),
* BigEndian (Boolean)
*/
format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
(float)dblSampleRate,
16,
1,
2,
(float)dblSampleRate,
false);
DataLine.Info targetInfo = new
DataLine.Info(TargetDataLine.class, format);
DataLine.Info sourceInfo = new
DataLine.Info(SourceDataLine.class, format);
try {
/*
* A source data line is written to
*/
sourceLine =
(SourceDataLine)AudioSystem.getLine(sourceInfo);
sourceLine.open(format); // Typical buffer size is same
as samplerate in bytes
sourceLine.start();
/*
* A target data line is read from
*/
targetLine =
(TargetDataLine)AudioSystem.getLine(targetInfo);
targetLine.open(format); // Typical buffer size is same
as samplerate in bytes
targetLine.start();
}
catch (LineUnavailableException e1) {
return false;
}
catch (SecurityException e2) {
return false;
}
catch (IllegalArgumentException e3) {
return false;
}
catch (IllegalStateException e4) {
return false;
}
if(!AudioSystem.isLineSupported(targetInfo)) {
return false;
}
sound = new AudioInputStream(targetLine);
return true;
}
/*
* Stop, flush, and close the soundcard interface
*/
public void closePCM() {
sourceLine.stop();
targetLine.stop();
sourceLine.flush();
targetLine.flush();
try {
sourceLine.close();
targetLine.close();
}
catch (SecurityException e)
{
}
}
/*
* Provide a block of Signed 16 bit PCM sound data
*/
public int getPCM(int[] intSampleArray) {
int intBytesRead;
byte[] byteData = new byte[intSampleArray.length * 2]; //
Convert count to bytes
/*
* Read bytes into array. This call will block if there aren't
* enough requested bytes.
*/
try {
intBytesRead = sound.read(byteData, 0, byteData.length);
} catch(IOException e) {
return -1;
}
/*
* This is designed for Little-Endian Intel machines
*/
for (int i = 0, j = 0; i < intBytesRead; i += 2, j++)
intSampleArray[j] = (byteData[i + 1] << 8) + byteData[i];
return intBytesRead / 2; // convert count to words
}
}
- 6
- Help sought trying to add java to mozilla 1.5
I've downloaded and gotten mozilla 1.5 to work on my desktop machine.
However, when I visit Java enabled sites, I get a popup that tells
me I am missing the plugin for the java-vm applet type. When I say
"download it", the only links are for windows and linux, and I'm
not using either of these.
In the java 1.4.2_01 directory I have on my machine is a rje/plugin/sparc/ns610
directory in which there is a .so file. But I don't see any instructions
on what all I need to connect things together.
When I try to copy that .so file into my $HOME/.mozilla/plugins directory,
mozilla 1.5 crashes attempting to access the java applets. If I
remove the .so, then I get a popup telling me I need a plugin.
Can anyone provide additional ideas on what might be missing?
--
<URL: http://wiki.tcl.tk/ > In God we trust.
Even if explicitly stated to the contrary, nothing in this posting
should be construed as representing my employer's opinions.
<URL: mailto:email***@***.com > <URL: http://www.purl.org/NET/lvirden/ >
- 9
- writing java daemon server: start and stopDear everyone,
I am trying to write a server program to do some monitoring.
I am using Windows 2000 platform.
I've seen that there is some server program can start server by
specifying command like "server start" and stop it like "server stop".
I am wondering how to do it in java language since java is running in
the JVM.
1. Is it prossible to send signal to kill the process just like c lang
?
2. Do java have process ?
3. How about if java thread can be killed by those deprecated method
like thread.stop(), can I find the current running thread and stop it
?
4. Any suggested method to do the server stop which can stop the
current running java program in JVM ?
Thank you for helping
Calvin
- 9
- Help with JavaPOS pleaseHi there,
I have made an application that uses a POS printer device to print out a
receipt,
but there are genereal problems printing out .....
sometimes it prints out sometimes it doesn't (??) this is not the most major
of the
problems. The most major problem has to do with setting the style and the
layout of the printing.
After I have opened my device, claimed it everything should be ready or ??
I have checked to see what the method getFontTypefaceList()); returns
and my guess was that these numbers return different numbers that are
representatives for character sets eg fonts!!!! So I take one of these
numbers to try it out, put a number inside the method setCharacterSet(850);
yes .. 850 for instamce ... then I restart my application to see if the
output
is different, but it is not. I wonder why.
and yes I have tried several other methods in the POSprinter class and
by means of the POSprinterConst class too.
Does anyone have any experience with this or am I left to keep
experimenting?
I also need to find out how to set Linebreaking, linedistancing etc etc bold
italic and so on.
Regards
Carl
- 9
- 9?. Steps To Improve Your FlyingThere are many things that you can do when you fly to make yourself a
safer and better pilot. Too many pilots get careless and stop doing
fundamental things that could save their lives. Here are some simple
things that you can do to improve your flying.
1. Use your rudder pedals.
It seems simple, right? Well, too many people neglect to get in the
good habit of using them. Use them during taxi, takeoff, climbs,
cruise, maneuvers, descents, and landing. Get the picture - Use them
all the time.
You can know exactly how much to use them during flight by looking at
the slip/skid indicator. That is the ball of the turn coordinator. As
long as the ball is centered between the lines, you are using the
right amount of rudder. If the ball is outside the lines, add rudder
in the direction that the ball is located.
For instance, if the ball is to the right, add right rudder. An easy
way to remember this is to "Step on the ball." Add enough pressure to
re-center the ball.
There are a lot of things happening when you are airborne. Correctly
using your rudder will make you a better pilot, keep your passengers
happy, and show your piloting professionalism (something you need to
have, even if you are not a professional pilot). Remember, step on the
ball.
2. Use Your Checklist
As you are flying, make sure that you use your checklist for each
portion of the flight. There are checklists for everything from
preflight to securing the airplane. Most airplanes have a checklist in
the owner's manual that you can use during your flights. Also, when
you learn to fly most flight schools have checklists that are
available for their students.
But checklists aren't put there to look pretty. Your job is to use
them. If you get in the habit of using one each flight, you will be
that much safer. It's not going to do you any good in your flight bag.
Even if you know the items by heart, still double check yourself
anyway.
Another thing, if you need to add something personal to your checklist
(like don't forget your sunglasses, or turn off your cell phone so the
battery won't run down as it searches for a signal in flight) do this
as well. As long as you have all the required items included, add any
that will help you personally during your flight.
3. G.U.M.P.S.
Whether you use G.U.M.P.S. as your landing checklist or not, get in
the habit of using a memorized checklist for your return to earth. In
a complex airplane, Gumps is; Gas, Undercarriage, Mixture, Propeller,
and Seatbelts. In a non-complex airplane, Gumps could be; Gas,
Undercarriage, Mixture, Power, and Seatbelts. Of course you don't
actually have to lower your gear on a fixed gear plane, but it is best
to remind yourself anyway. That way, when you do transfer to a
retractable gear airplane, you won't have to add anything to your
checklist. This also happens to be one of the most important checklist
items of the whole flight. So you will already be in the habit of
checking your landing gear when you get to the point where it really
matters.
4. Weight and Balance
Never ever forget to precisely calculate your weight and balance for
each flight. Too many people have gotten lazy and careless, and have
added extra weight in the form of passengers or cargo to their
airplanes, thinking that everything is ok. Isn't there room for error
- a little safety cushion, if you will - in the maximum useful load?
Why would you even want to know? If you take this attitude with your
flying, you are putting yourself and your passengers in a very
dangerous situation. Never operate out of the manufacturer's set
limitations for your airplane. They are there for a reason; to keep
you safe!
5. T.O.L.D.
Takeoff and Landing Data should be calculated for every flight as
well. Make sure that you are very familiar with all of the runways of
intended use and their lengths and widths. If it is not something that
you or your airplane can handle, don't make the flight. Don't get in
the habit of assuming that just because you are in a Cessna 172 that
every landing strip is suitable for your flight. Calculate your
takeoff and landing distances for each flight, taking into
consideration the density altitude and aircraft performance.
6. Appropriate Radio Calls
One flying safety item that can easily be performed is making sure
that you make your radio calls at the appropriate time. Whether you
are flying out of a towered or uncontrolled airport, be professional
with your radio calls. One common error is made at uncontrolled
airports, when after an airplane lands, the pilot calls clear of the
runway while part or all of the airplane is on the runway side of the
hold short line. This is dangerous! What if your airplane malfunctions
and you are stuck on the runway and another airplane thinks it's safe
to land? This is a hazardous situation that can easily be avoided. At
non-towered airports, it's better to not make any radio call at all,
than to make a dangerous one. Get it right!
7. Complete Runup
You have done a complete preflight inspection and are now ready to
takeoff. Make sure you do a complete engine runup as well. Check every
aircraft system while you are still on the ground before you get in
the air. Determine that all of your radios, comm and nav are
functioning. Check your vacuum and electric gyros. Check your flight
controls and your engine gauges. Know that when you take off, you are
as safe as you can be. There is no reason to rush through your runup.
8. Situational Awareness
Situational awareness is when you know exactly what is happening with
your flight and with what is going on around you. On the ground, you
need to make sure that you are aware of other airplanes that are
taxiing and using the runway. In the air, use the radio and your eyes
to know exactly where other airplanes are in relation to you as well
as their intentions. But situational awareness is not just limited to
knowing where other airplanes are. You also need to know exactly what
is happening with your airplane, the weather, airspace, the winds,
your location, what you would do in an emergency, etc. Regardless of
whether you are flying cross country or local, for fun or for
training, don't assume everything is alright. Know what is happening
around you.
9. Fly the plane from engine start to shutdown
When it comes to flying, make sure that you are maintaining vigilance
at all times in the airplane. Too many times pilots zone out at some
point in the flight. For many pilots, that time is before takeoff and
after landing. Make sure that even when you are on the ground, you are
flying the airplane. Keep a watchful eye out for other aircraft and
don't rely on the tower to separate ground traffic. Position your
flight controls so that you have the proper crosswind correction,
regardless of the wind speed. Even if the wind is calm, look at the
wind sock and taxi as if the wind is really blowing in the direction
indicated by the sock. Although you are on the ground, your control
surfaces are still somewhat effective. Treat them as if your safety
depends on their position.
9?. Have Fun
Even though it sounds simple, keep your flying fun. When you are in
the air, you are living a dream. Don't forget it!
http://cncarrental.cn/html/goodspeech/20060924/633.html
- 9
- Can I restrict permissions at runtime?I have an editor application that I've writen that needs to read and
write XML files to disk. I'd like to extend this program by allowing
users to extend my editor by plugging in custom code they compile using
certain interfaces. My editor will call their code to gain use of
their functions.
However, this plugin code is untrusted, and I don't want it to access
the filesystem or network. Is there some way I can create a sandbox
within my program in which I can run this custom code and be sure that
it cannot do things like write to the filesystem? Perhaps create a
separate thread with special restricted permissions?
Mark McKay
- 11
- 11
- Problem with IN parameters to an Oracle stored procedureHello all
I had earlier posted the same problem I am having on
comp.java.lang.programmer earlier and someone suggested this post
would probably fall better under this group. Here is the link to the
original post with the original post copy pasted below.
http://groups.google.co.in/group/comp.lang.java.programmer/browse_thread/thread/b0b845981c3e403a/#
Since then I have changed the IN parameter to my stored procedure to
read as
clID IN TABLEA.CLIENTID%TYPE
instead of clientID, based on a suggestion to the earlier post and
have still had no luck.
Any suggestions are welcome.
Thanks
Swetha
- 13
- Beans with JSFI'm pretty new to programming with JSF and beans, and have been
reading up the documentation in the book "Core JavaServer Faces"
by D.Geary and C. Horstmann as well as online, and managed to
get some simple programs to run, so at least I now understand
some of the basics.
However, I've got quite a lot of existing code in HTML and
JavaScript that works, although not fully cleaned up yet, and I want
to make as few changes as possible in order to modify it for using
beans with JSF. Specifically, some months ago I wrote some
client-side code which is backed up online at
http://csharp.com/simulator/simulator.html, which I'm in the process
of modifying for JSF. The links at the bottom take you to
.../option1.html and .../option2.html, with the original source code
at
respectively .../option1.txt and .../option2.txt. At the moment the
code is not linked to code on a server, so only the JavaScript works
with the forms.
The index page didn't need much work, with the main change being
to include the JSF tags at the top (I'm leaving work on the counter
until later). The option1 page is mostly one large form, and what I
have since done is to keep the form as it is, except that it only
operates with JavaScript, with the post, action, and JavaScript
function calls at the beginning removed, together with the "Submit"
and "Reset" buttons at the end. I put these two buttons together
with calls to the JavaScript in a JSF form immediately below the
end of original form, and after making a few changes to the
JavaScript, got the JavaScript to work correctly and validate the
form.
My question is how do I send to the server the contents of the
original form, including the hidden fields? Do I have to create a
hidden field in the JSF form for each value entered in the main form,
and create a bean for each of these values, or is there some way
of sending the whole contents of the form to a bean, which can then
parse the values. I want to avoid turning the original form into a
JSF form, as it would probably mean making many changes to the
JavaScript, which would require extra work and debugging.
Exactly the same will be done with the option2 page once option1
has been sorted out, and I would be most grateful for some advice.
Christopher Sharp
- 15
- Toward more efficient ArrayListsRoedy Green (email***@***.com) wrote:
: IIRC Arraylists are about 10 times slower than plain arrays. This is
: quite a penalty to pay for not knowing ahead of time how many items
: you will have.
Can you give a pointer to a benchmark that shows this?
Or can you build a benchmark that shows this?
Can you give proof that this really is your hot spot? Most guesses
about what to optimize is wrong.
Anyway I find it hard to believe that arraylist is 10 times slower
since the methods (get and set) does something like
{ RangeCheck(index); return elementData[index]; }.
Ok the range check is unneccasry, it will be checked by the jvm also.
If you use add a lot then it will check the size of the array and
expand if neccessary. If you know in advance how many objects you will
store this should not be a problem (you do create the list with the
size), if you dont know in advance it will be hard to write something
that is a magnitude faster...
/robo
- 15
- List helpHi,
I am new to Java.
I've been working on this project for some time now and I cannot get it
to work.
This is supposed to be a linked list.
I need to use an insert method that alphabetically adds a new title to
the list. This code I have here doesn't have a working compareTo method
but only a test to add node to the list.
This code was provided to me and I must add an insert that will put a new
item in alphabetically order. Don't tell me the answer - I just don't
understand why this doesn't work. I hope that what I've written here is
clear.
Thanks
John
Main looks like this something like this:
main(String [] args){
BookList book = new BookList();
book.add (new Book ("title of book"));
}
// ----------------Test compareTo
public int compareTo(Node a, Node b){
// Since I couldn't get this to work either, I test to see if I can get
any value.
println(a.book.compareTo(b.book)); // doesn't work I don't know how to
compare the titles
return 0;
}
public class BookList
{
private BookNode head;
//----------------------------------------------------------------
// Sets up an initially empty list of books.
//----------------------------------------------------------------
BookList()
{
head = null;
}
//----------------------------------------------------------------
// Creates a new Book object and adds it to the end of
// the linked list.
//----------------------------------------------------------------
public void insert (Book newBook){
BookNode node = new BookNode (newBook);
BookNode current;
BookNode prev;
if (head == null)
head = node;
else
{
current = head;
while (current.next != null){
// Orignally this method looped through the whole list until it found the
end, then add the new
// to the bottom.
// I did a test here to see if I could move the list around.
// This is what I think should happen: save current in prev. get next with
current.
// try to put node in from of current.next. It seems no matter what I try
there's a null pointer
// error. I just can't figure this out.
prev = current;
current = current.next;
node.prev = current.prev;
node.next = current;
node.prev.next = node;
current.prev = node;
}
current.next = node;
}
}
//*****************************************************************
// An inner class that represents a node in the book list. The
// public variables are accessed by the BookList class.
//*****************************************************************
private class BookNode
{
public Book book;
public BookNode next;
public BookNode prev;
//--------------------------------------------------------------
// Sets up the node
//--------------------------------------------------------------
public BookNode (Book theBook)
{
book = theBook;
next = null;
prev = null;
}
}
}
|
| Author |
Message |
rohayre

|
Posted: 2007-1-12 11:07:00 |
Top |
java-programmer, Play audio clip in an Application
I'm trying to play an audio clip by using Applet's newAudioClip()
method. That method takes a URL. The .wav file is located in a jar file
(the only jar file). For example:
if myJar.jar is the only jar file
"java -jar myJar.jar" launches the application correctly and everything
is wonderful. My audio clip won't play because I don't know how to
access the .wav file from the jar file.
This code snippet works fine when I'm not running from the jar file:
try
{
File currentDir = new File(".");
URL currentDirURL = currentDir.toURL();
URL url = new URL(currentDirURL, fileName);
AudioClip clip = Applet.newAudioClip(url);
clip.play();
}
catch (Exception e)
{
e.printStackTrace();
}
It knows to look for the sound file in the current directory. How do I
adjust this code to look for the sound file in the jar.
I have a feeling it's an easy answer involving class.getResource().....
|
| |
|
| |
 |
Knute Johnson

|
Posted: 2007-1-12 11:19:00 |
Top |
java-programmer >> Play audio clip in an Application
email***@***.com wrote:
> I'm trying to play an audio clip by using Applet's newAudioClip()
> method. That method takes a URL. The .wav file is located in a jar file
> (the only jar file). For example:
> if myJar.jar is the only jar file
> "java -jar myJar.jar" launches the application correctly and everything
> is wonderful. My audio clip won't play because I don't know how to
> access the .wav file from the jar file.
>
> This code snippet works fine when I'm not running from the jar file:
>
> try
> {
> File currentDir = new File(".");
> URL currentDirURL = currentDir.toURL();
> URL url = new URL(currentDirURL, fileName);
> AudioClip clip = Applet.newAudioClip(url);
> clip.play();
> }
> catch (Exception e)
> {
> e.printStackTrace();
> }
>
> It knows to look for the sound file in the current directory. How do I
> adjust this code to look for the sound file in the jar.
>
> I have a feeling it's an easy answer involving class.getResource().....
>
You answered it yourself - URL Class.getResource(String name)
--
Knute Johnson
email s/nospam/knute/
|
| |
|
| |
 |
rohayre

|
Posted: 2007-1-16 11:44:00 |
Top |
java-programmer >> Play audio clip in an Application
Does anyone know why this wont play? The wav file is located in the jar
file found on the classpath. What am I missing?
import java.applet.Applet;
import java.applet.AudioClip;
import java.net.URL;
public class SoundPlayer
{
public void playSiren()
{
URL url = this.getClass().getResource("threeHorn.wav");
AudioClip clip = Applet.newAudioClip(url);
clip.play();
}
public static void main(String[] args)
{
new SoundPlayer().playSiren();
}
}
Knute Johnson wrote:
> email***@***.com wrote:
> > I'm trying to play an audio clip by using Applet's newAudioClip()
> > method. That method takes a URL. The .wav file is located in a jar file
> > (the only jar file). For example:
> > if myJar.jar is the only jar file
> > "java -jar myJar.jar" launches the application correctly and everything
> > is wonderful. My audio clip won't play because I don't know how to
> > access the .wav file from the jar file.
> >
> > This code snippet works fine when I'm not running from the jar file:
> >
> > try
> > {
> > File currentDir = new File(".");
> > URL currentDirURL = currentDir.toURL();
> > URL url = new URL(currentDirURL, fileName);
> > AudioClip clip = Applet.newAudioClip(url);
> > clip.play();
> > }
> > catch (Exception e)
> > {
> > e.printStackTrace();
> > }
> >
> > It knows to look for the sound file in the current directory. How do I
> > adjust this code to look for the sound file in the jar.
> >
> > I have a feeling it's an easy answer involving class.getResource().....
> >
>
> You answered it yourself - URL Class.getResource(String name)
>
> --
>
> Knute Johnson
> email s/nospam/knute/
|
| |
|
| |
 |
Andrew Thompson

|
Posted: 2007-1-16 12:04:00 |
Top |
java-programmer >> Play audio clip in an Application
email***@***.com wrote:
Please refrain from top-posting.
> Does anyone know why this wont play? The wav file is located in the jar
> file found on the classpath. What am I missing?
The only thing I can think of, is that perhaps the
classloader is the bootstrap classloader (and
therefore will not find the application resource).
> URL url = this.getClass().getResource("threeHorn.wav");
^
(as an aside, please change tabs to 3 or 4 spaces before
posting, the '^' character above lines up with where I am
seeing the code start)
To test that theory, try printing the details of the
classloader at this point in the code..
ClassLoader cl = this.getClass().getClassLoader();
System.out.println( "ClassLoader: " + cl );
URL url = cl.getResource("threeHorn.wav");
..does it tell you the classloader is 'null'?
And another thing, are you locked into 1.2*, or can
you go to 1.3+? If so - it might be worth looking into
the java.sound.sampled package introduced with 1.3
(though it may also be overkill, for this simple problem.)
* It seems your current code would be compatible with
Java 1.2+, unless I missed something.
Andrew T.
|
| |
|
| |
 |
Knute Johnson

|
Posted: 2007-1-17 1:51:00 |
Top |
java-programmer >> Play audio clip in an Application
email***@***.com wrote:
> Does anyone know why this wont play? The wav file is located in the jar
> file found on the classpath. What am I missing?
>
> import java.applet.Applet;
> import java.applet.AudioClip;
> import java.net.URL;
>
> public class SoundPlayer
> {
> public void playSiren()
> {
> URL url = this.getClass().getResource("threeHorn.wav");
> AudioClip clip = Applet.newAudioClip(url);
> clip.play();
> }
>
> public static void main(String[] args)
> {
> new SoundPlayer().playSiren();
> }
> }
>
Looks like the program is ending before the AudioClip can play. Try
putting a sleep after playSiren();
--
Knute Johnson
email s/nospam/knute/
|
| |
|
| |
 |
chump

|
Posted: 2007-1-17 3:12:00 |
Top |
java-programmer >> Play audio clip in an Application
Andrew....
Thanks for you help. Few things:
- What is top-posting?
- The classloader is not null. I am running java 1.5 in eclipse on
MacOSX. The classloader is printing out
"sun.misc.Launcher$AppClassLoader@a9c85c"
Still looking.....
Andrew Thompson wrote:
> email***@***.com wrote:
>
> Please refrain from top-posting.
>
> > Does anyone know why this wont play? The wav file is located in the jar
> > file found on the classpath. What am I missing?
>
> The only thing I can think of, is that perhaps the
> classloader is the bootstrap classloader (and
> therefore will not find the application resource).
>
> > URL url = this.getClass().getResource("threeHorn.wav");
> ^
> (as an aside, please change tabs to 3 or 4 spaces before
> posting, the '^' character above lines up with where I am
> seeing the code start)
>
> To test that theory, try printing the details of the
> classloader at this point in the code..
> ClassLoader cl = this.getClass().getClassLoader();
> System.out.println( "ClassLoader: " + cl );
> URL url = cl.getResource("threeHorn.wav");
>
> ..does it tell you the classloader is 'null'?
>
> And another thing, are you locked into 1.2*, or can
> you go to 1.3+? If so - it might be worth looking into
> the java.sound.sampled package introduced with 1.3
> (though it may also be overkill, for this simple problem.)
>
> * It seems your current code would be compatible with
> Java 1.2+, unless I missed something.
>
> Andrew T.
|
| |
|
| |
 |
chump

|
Posted: 2007-1-17 3:20:00 |
Top |
java-programmer >> Play audio clip in an Application
It's throwing a null pointer exception before it gets a chance to
end....
java.lang.NullPointerException
at sun.applet.AppletAudioClip.<init>(AppletAudioClip.java:48)
at java.applet.Applet.newAudioClip(Applet.java:273)
at com.gizmo.util.SoundPlayer.playSiren(Unknown Source)
at com.gizmo.util.SoundPlayer.main(Unknown Source)
sleeping...
Ending...
Knute Johnson wrote:
> email***@***.com wrote:
> > Does anyone know why this wont play? The wav file is located in the jar
> > file found on the classpath. What am I missing?
> >
> > import java.applet.Applet;
> > import java.applet.AudioClip;
> > import java.net.URL;
> >
> > public class SoundPlayer
> > {
> > public void playSiren()
> > {
> > URL url = this.getClass().getResource("threeHorn.wav");
> > AudioClip clip = Applet.newAudioClip(url);
> > clip.play();
> > }
> >
> > public static void main(String[] args)
> > {
> > new SoundPlayer().playSiren();
> > }
> > }
> >
>
> Looks like the program is ending before the AudioClip can play. Try
> putting a sleep after playSiren();
>
> --
>
> Knute Johnson
> email s/nospam/knute/
|
| |
|
| |
 |
Knute Johnson

|
Posted: 2007-1-17 6:37:00 |
Top |
java-programmer >> Play audio clip in an Application
chump wrote:
> It's throwing a null pointer exception before it gets a chance to
> end....
>
> java.lang.NullPointerException
> at sun.applet.AppletAudioClip.<init>(AppletAudioClip.java:48)
> at java.applet.Applet.newAudioClip(Applet.java:273)
> at com.gizmo.util.SoundPlayer.playSiren(Unknown Source)
> at com.gizmo.util.SoundPlayer.main(Unknown Source)
> sleeping...
> Ending...
>
>
> Knute Johnson wrote:
>> email***@***.com wrote:
>>> Does anyone know why this wont play? The wav file is located in the jar
>>> file found on the classpath. What am I missing?
>>>
>>> import java.applet.Applet;
>>> import java.applet.AudioClip;
>>> import java.net.URL;
>>>
>>> public class SoundPlayer
>>> {
>>> public void playSiren()
>>> {
>>> URL url = this.getClass().getResource("threeHorn.wav");
>>> AudioClip clip = Applet.newAudioClip(url);
>>> clip.play();
>>> }
>>>
>>> public static void main(String[] args)
>>> {
>>> new SoundPlayer().playSiren();
>>> }
>>> }
>>>
>> Looks like the program is ending before the AudioClip can play. Try
>> putting a sleep after playSiren();
>>
>> --
>>
>> Knute Johnson
>> email s/nospam/knute/
>
Do you have the .wav file in the jar? I get that error if it isn't in
the jar.
--
Knute Johnson
email s/nospam/knute/
|
| |
|
| |
 |
Andrew Thompson

|
Posted: 2007-1-17 10:29:00 |
Top |
java-programmer >> Play audio clip in an Application
chump wrote:
> Andrew....
>
> Thanks for you help.
You're welcome.
>...Few things:
>
> - What is top-posting?
I'm glad you asked. But instead of answering, I'll
demonstrate a handy technique that will answer that,
as well as many other question later questions..
<http://www.google.com/search?q=definition+top-post>
Note that by changing anything after 'definition', you
get the meaning of the word or phrase within one or
two more clicks (usually).
> - The classloader is not null. I am running java 1.5 in eclipse on
> MacOSX. The classloader is printing out
> "sun.misc.Launcher$AppClassLoader@a9c85c"
OK - thanks for confirming that is not the problem.
> Still looking.....
I'll review the rest of the thread..
Andrew T.
|
| |
|
| |
 |
chump

|
Posted: 2007-1-18 1:56:00 |
Top |
java-programmer >> Play audio clip in an Application
I've been able to play an audio clip with the code below. Only problem
now is the thread won't die and the app stays running.
Does the thread need to be set as Deamon?
import java.io.File;
import java.io.IOException;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineEvent;
import javax.sound.sampled.LineListener;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
/**
* This class provides simple functions for playing sounds
*
* @author ryan
*/
public class SoundPlayer implements LineListener, Runnable
{
private File soundFile;
private Thread thread;
private static SoundPlayer player;
/**
* Private because of the singleton
*/
private SoundPlayer()
{
}
/**
* Play a siren sound
*/
public static void playSiren()
{
SoundPlayer p = getPlayer();
p.playSirenFile();
}
/**
* Play the siren file
*/
private void playSirenFile()
{
this.soundFile = new File("./audio/threeHorn.wav");
thread = new Thread(this);
thread.setName("SoundPlayer");
thread.start();
}
/**
* Invoked when the thread kicks off
*/
public void run()
{
try
{
AudioInputStream stream = AudioSystem
.getAudioInputStream(this.soundFile);
AudioFormat format = stream.getFormat();
/**
* we can't yet open the device for ALAW/ULAW playback, convert
* ALAW/ULAW to PCM
*/
if ((format.getEncoding() == AudioFormat.Encoding.ULAW)
|| (format.getEncoding() == AudioFormat.Encoding.ALAW))
{
AudioFormat tmp = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED,
format.getSampleRate(),
format.getSampleSizeInBits() * 2, format.getChannels(),
format.getFrameSize() * 2, format.getFrameRate(), true);
stream = AudioSystem.getAudioInputStream(tmp, stream);
format = tmp;
}
DataLine.Info info = new DataLine.Info(Clip.class, stream
.getFormat(), ((int) stream.getFrameLength() * format
.getFrameSize()));
Clip clip = (Clip) AudioSystem.getLine(info);
clip.addLineListener(this);
clip.open(stream);
clip.start();
try
{
thread.sleep(99);
}
catch (Exception e)
{
}
while (clip.isActive() && thread != null)
{
try
{
thread.sleep(99);
}
catch (Exception e)
{
break;
}
}
clip.stop();
clip.close();
}
catch (UnsupportedAudioFileException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (LineUnavailableException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static SoundPlayer getPlayer()
{
if (player == null)
{
player = new SoundPlayer();
}
return player;
}
public void update(LineEvent event)
{
}
public static void main(String[] args)
{
SoundPlayer.playSiren();
}
}
|
| |
|
| |
 |
Knute Johnson

|
Posted: 2007-1-18 3:10:00 |
Top |
java-programmer >> Play audio clip in an Application
chump wrote:
> I've been able to play an audio clip with the code below. Only problem
> now is the thread won't die and the app stays running.
>
> Does the thread need to be set as Deamon?
>
> import java.io.File;
> import java.io.IOException;
>
> import javax.sound.sampled.AudioFormat;
> import javax.sound.sampled.AudioInputStream;
> import javax.sound.sampled.AudioSystem;
> import javax.sound.sampled.Clip;
> import javax.sound.sampled.DataLine;
> import javax.sound.sampled.LineEvent;
> import javax.sound.sampled.LineListener;
> import javax.sound.sampled.LineUnavailableException;
> import javax.sound.sampled.UnsupportedAudioFileException;
>
> /**
> * This class provides simple functions for playing sounds
> *
> * @author ryan
> */
> public class SoundPlayer implements LineListener, Runnable
> {
> private File soundFile;
>
> private Thread thread;
>
> private static SoundPlayer player;
>
> /**
> * Private because of the singleton
> */
> private SoundPlayer()
> {
> }
>
> /**
> * Play a siren sound
> */
> public static void playSiren()
> {
> SoundPlayer p = getPlayer();
> p.playSirenFile();
> }
>
> /**
> * Play the siren file
> */
> private void playSirenFile()
> {
> this.soundFile = new File("./audio/threeHorn.wav");
> thread = new Thread(this);
> thread.setName("SoundPlayer");
> thread.start();
> }
>
> /**
> * Invoked when the thread kicks off
> */
> public void run()
> {
> try
> {
> AudioInputStream stream = AudioSystem
> .getAudioInputStream(this.soundFile);
> AudioFormat format = stream.getFormat();
>
> /**
> * we can't yet open the device for ALAW/ULAW playback, convert
> * ALAW/ULAW to PCM
> */
> if ((format.getEncoding() == AudioFormat.Encoding.ULAW)
> || (format.getEncoding() == AudioFormat.Encoding.ALAW))
> {
> AudioFormat tmp = new AudioFormat(
> AudioFormat.Encoding.PCM_SIGNED,
> format.getSampleRate(),
> format.getSampleSizeInBits() * 2, format.getChannels(),
> format.getFrameSize() * 2, format.getFrameRate(), true);
> stream = AudioSystem.getAudioInputStream(tmp, stream);
> format = tmp;
> }
> DataLine.Info info = new DataLine.Info(Clip.class, stream
> .getFormat(), ((int) stream.getFrameLength() * format
> .getFrameSize()));
>
> Clip clip = (Clip) AudioSystem.getLine(info);
> clip.addLineListener(this);
> clip.open(stream);
> clip.start();
> try
> {
> thread.sleep(99);
> }
> catch (Exception e)
> {
> }
> while (clip.isActive() && thread != null)
> {
> try
> {
> thread.sleep(99);
> }
> catch (Exception e)
> {
> break;
> }
> }
> clip.stop();
> clip.close();
> }
> catch (UnsupportedAudioFileException e)
> {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> catch (IOException e)
> {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> catch (LineUnavailableException e)
> {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> }
>
> private static SoundPlayer getPlayer()
> {
> if (player == null)
> {
> player = new SoundPlayer();
> }
> return player;
> }
>
> public void update(LineEvent event)
> {
> }
>
> public static void main(String[] args)
> {
> SoundPlayer.playSiren();
> }
> }
>
Here is how to play a Clip. But what was wrong with using AudioClip?
import java.io.*;
import javax.sound.sampled.*;
public class PlayClip {
public static void main(String[] args) {
try {
AudioInputStream ais =
AudioSystem.getAudioInputStream(new File(args[0]));
AudioFormat af = ais.getFormat();
Clip line = AudioSystem.getClip();
line.open(ais);
line.start();
line.drain();
line.stop();
line.close();
} catch (Exception e) {
System.out.println(e);
}
}
}
--
Knute Johnson
email s/nospam/knute/
|
| |
|
| |
 |
chump

|
Posted: 2007-1-19 11:55:00 |
Top |
java-programmer >> Play audio clip in an Application
I ran your app. It works, plays the file and is very clean. One
thing... my app doesn't go down after the file plays. In my previous
example, I thought it was the thread I was spinning off wouldn't die,
but your code doesn't create a new thread and it still stays up for me.
Are any of the audio classes hanging onto something that is keeping the
app up?
|
| |
|
| |
 |
Knute Johnson

|
Posted: 2007-1-19 13:00:00 |
Top |
java-programmer >> Play audio clip in an Application
chump wrote:
> I ran your app. It works, plays the file and is very clean. One
> thing... my app doesn't go down after the file plays. In my previous
> example, I thought it was the thread I was spinning off wouldn't die,
> but your code doesn't create a new thread and it still stays up for me.
> Are any of the audio classes hanging onto something that is keeping the
> app up?
>
There is a change in Java Sound, I think between 1.4 and 1.5. In 1.4
there is a thread created that will hold the program and in 1.5 that was
fixed. I tried my code in 1.6 and there is another wrinkle with it. It
won't play the file unless you put a very short sleep after the start()
call. Java Sound has unfortunately not been a high priority for Sun and
there are some inconsistencies.
If you are going to use this in a production environment you might want
to consider using a LineListener to control the actions of your program.
--
Knute Johnson
email s/nospam/knute/
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- 2
- Eclipse 3.3 - external tool arguments issue.
I run the WebSphere command line wsadmin java tool as external tool in
Eclipse. It works fine except where an External tool argument has an
"=" sign as in "-javaoption -Dcom.ibm.ws.management.standalone2=xxxx".
Wsadmin picks up the "-Dcom.ibm.ws.management.standalone2" variable
but not the value. Seems that the Eclipse "arguments" dialog
truncates values after the "=" sign. Is there a way around this.
The arguments are listed below.
-user 1234 -password xyz
-lang jacl -host 11.11.11.11. -port 1111
-javaoption -Dcom.ibm.ws.management.standalone2=xxxx
-wsadmin_classpath C:\WASAdminSBV\WSAdmin\WAS5.1\JACL\proclib.jar
-f ${resource_loc}
The problem does not occur when Wsadmin is run from the command line.
- 3
- Opportunities in U.K./Great Britain?I have a friend who recently moved to Madrid. He had a Dutch passport
so EU access was relatively easy for him. We both lived in D.C., but
I remain US citizen by birth.
My question is, he says it's becoming more popular for J2EE
development in Great
Britain and the UK. I'm wondering how good is the market? (in
relation to US) How good is it for US programmers? (any demand for US
borne skills) And if any of these are true, how hard it is securing
work permit? (etc) Finally is there any idea what standard of living
might be like?
Given all of this would there be sacrifices, or would it just be
better overall simply to stay in US?
- 4
- load servlet mappings at runtime in tomcatCan anyone suggest a way to achieve dynamic servlet mappings in tomcat 5.5.
What I want to do is run a web app with any number of paths all pointing to
one servlet. These paths would be loaded from a database and extra paths
can be added at runtime by the user. So an example would be
www.domain.com/sample and www.domain.com/anothersample would both execute
the same servlet.
Another option I thought of was having a custom 404 servlet that would check
the request supplied and then redirect.
- 5
- Four Mobile Phone Makers to Create Linux Platform
Roy Schestowitz wrote:
> Mobile phone companies join forces on Linux
>
> ,----[ Quote ]
> | Four mobile handset makers are teaming up with two cellular operators
> | to develop a new Linux software platform for mobile devices.
> |
> |
> | Cell phone makers Motorola, NEC, Panasonic Mobile Communications and
> | Samsung Electronics, along with mobile operators NTT DoCoMo and Vodafone,
> | expect to announce on Thursday plans to form an independent foundation to
> | develop a common mobile Linux-based platform. They will use this platform
> | to develop new products, applications and features.
> |
> | Linux, an open-source operating system, is already available on a wide
> | range of mobile handsets. Motorola alone says it has shipped more than
> | 5 million Linux-based handsets, mostly on smart phones, such as the
> | Ming model shipped in China. In addition, Motorola just launched the new
> | Rokr E2 music phone in Asia, which also uses Linux. The Rokr E2 will
> | soon ship in Europe.
> `----
>
> http://news.com.com/2100-1039_3-6083883.html?part=rss&tag=6083883&subj=news
>
> If this is not proof of GNU/Linux taking over, I don't know what is... Nokia,
> Palm and others are no exception.
Symbian is by far the dominant mobile OS worldwide and don't see that
changing soon, although tons of linux phone shipments to china, which
has the largest mobile subscriber base in the world holds hope.
As always, Java ME is the application platform for all these devices.
*Posted from my u know what...
- 6
- Ultimate enterprise design pattern for 3 tiered appsSo, I feel I am close here is what I have so far.
Goal: Database driven selection of controls on forms
Goal: Business rules only aware of interfaces
Goal: Presentation layer only aware of interfaces
Database Table Person: Name, BirthDate, Gender, CreateDate, CreatedBy
Value Object:
public class Person {
private String name;
private DateTime birthDate;
private int gender;
private DateTime createDate;
private int createdBy;
}
Business Layer Object:
public interface IPersonModel {
public boolean isTeenager();
public boolean isMale();
public boolean isFemale();
}
Presentation layer Multi Column List control
public interface ITableList {
public int rowCount();
public Object getItemAtRow(int row);
public Object getValueAtRowColumn(int row, int column);
}
public interface ITableItem {
public Object getValueAtColumn(int column);
}
The most complex part is storing in a database table which fields on
the value object will be presented in the multi column list control.
It needs to be user friendly and maintainable.
One time I tried having each value object with a switch statement for a
unique number for each field. So the database contents and source code
are kept in synch e.g. 266 in the database means 'Person CreateDate'
and the value object returns that when implementing ITableItem.
It worked but relies on a code generator to make it all work.
This time around I thought I could keep a script in the database so the
user would pick the first column to be person.getCreateDate(), the
second to be person.getName() etc.
Using reflection I could generate on the fly which attribute will be
displayed in which column.
Anyone think of other options?
The other thing I need to change is it seems an unecessary dependency
for the value object to implement ITableItem - there probably needs to
be another class which does it and depending on the database values
pulls the data from the value object.
The same goes for the value object implementing the business rules.
While probably not too bad if it does, perhaps mapping the values to
something that does might work better.
Apart from the value object I am trying to anything else in all the
code knowing about fields which are only used for CRUD e.g. createDate.
CreateDate may never be used for logic - in my app - ever - so why
pass it around as business objects - better to only have things
implementing interfaces where needed.
What do you think so far?
- 7
- Regular expressions question!I'm trying to parse HTML tables, so I need to find following pieces of text!
<table .....anything between this ..... /table> and
<tr ........ /tr> and
of course
<td> 'part that I need' </td>
I do not know how to put that into regular expression!
Thanks!
- 8
- How to convert a C++ Object to a JNI jobject in order to use GetObjectClassI have an interface object of type ISubscribe and I am trying to cast
the ISubscribe object to a jobject so I can call GetObjectClass in
order to proceed with a callback using JNI.
ISubscribe * s
jclass cls = env->GetObjectClass(s);
Does anyone know how I can do this in C++? I tried using
reinterpret_cast<jobject>(s) but GetObjectClass does not like that. Any
ideas would be appreciated.
Thanks,
Vijayk
- 9
- JDialog focusHi,
Is it possible to ensure that, upon setVisible(true), a JDialog pop-up
jumps on top of all other windows including other applications?
Many thanks in advance!
Aaron Fude
- 10
- ain't java grand ?I just got this error message from the java 4.2 compiler.
---
Consulting.java:152: cannot resolve symbol
symbol : variable $
location: class Consulting
perchance you meant '.'
---
Ain't it just the coolest message you've ever seen?
- 11
- using jsp:setProperty on non-simple types.Hi,
I'm currently having a small problem with my application. I'm using
some simple classes that wraps simple types to help me provide multiple
representation. For example, a DateCBO calls wraps the Date type and
gives me the oportunity to have various 'getters' like
getDateShortFormat(), getHtml(), getDateLongFormat() and so on.
My beans are using this kind of wrappers as their properties.
I have already made a custom tag to retrieve information that i use
instead of the standard jsp:getProperty
Now, i'm trying to use the jsp:setProperty to initialise the bean
property, but i have 'Could not coerce String to non-primitive type
StringCBO without bean property editor (JSP 1.2: 2.13.2.1) at line 13'
error.
Is there an interface that i can use to allow direct usage of
'jsp:setProperty', or should i create a custom tag as well.
thanks.
- 12
- ... to see if I can post ...
I attempted to respond to the response to my latest post,
or to thank him twice, but not shown. What is going on?
- 13
- mouseClicked vs. mousePressed on Apple vs. WindowsI'm writing a Swing component which must function similarly on Apple
and Windows; and am having trouble with which event to fire off of
(this is effectively a toggle button which would ideally just be
interested in mouseClicked). For a variety of other reasons, I don't
want to make my code act on the mousePressed event.
Originally, our QA person asserted that it was busted because she was
clicking (and moving the mouse > 10 pixels) and it wasn't getting
"toggled" (this was on Windows). I won the battle there by saying
"don't move it 10 pixels; that's a drag, not a click". (after
debugging and figuring out that if you moved the mouse more than
approximately that much, the mouseClicked never came in).
However, she now claims that on Apple (OSX) that the button fails to
toggle if you move the mouse even one pixel while pressing the button.
(i.e. if you are not perfectly still while clicking).
Obviously this would be a different story. I don't have immediate
access to an Apple machine, so was wondering if anybody else had seen
this behavior. When I worked on the AWT on OS/2 at IBM, it was fairly
clear that the mouse events were determined based on native operating
system events (i.e. when Windows says it is a click, we'll say it is a
click). Don't know if that's true now or not, since I haven't seen the
code since Java 1.1.8.
---
Mike Dahmus
m dah mus @ at @ io.com
- 14
- jni gcc mangled names//Crapo.java
public class Crapo {
static {
System.loadLibrary("Crapo");
}
native public static int magicNumber(int n);
public static void main(String... args) {
System.out.println(magicNumber(246));
}
}
//Crapo.c
typedef long long __int64;//gcc doesn't recognize __int64
#include "Crapo.h"
/*
* Class: Crapo
* Method: magicNumber
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_Crapo_magicNumber(JNIEnv * env, jclass c,
jint n) {
return 47;
}
//run gcc -mno-cygwin -Wl,--add-stdcall-alias -shared -o Crapo.dll -I
"C:\Program Files\Java\jdk1.6.0\include" -I "C:\Program
Files\Java\jdk1.6.0\include\win32" Crapo.c
//output of nm Crapo.dll
10003040 b .bss
10003020 b .bss
10003000 b .bss
//............ 30+ lines of this crap
1000505c i .idata$5
//..........................
100011d0 T _DllMain@12
10001000 T _DllMainCRTStartup@12
100011c0 T _Java_Crapo_magicNumber@12//<-----------------
10001360 T __CTOR_LIST__
10001368 T __DTOR_LIST__
U __RUNTIME_PSEUDO_RELOC_LIST_END__
U __RUNTIME_PSEUDO_RELOC_LIST__
//................... more crap; to me at least
//it was my understanding that --add-stdcall-alias when passed to the
linker should remove the @12 of _Java_Crapo_magicNumber@12
//run gcc -mno-cygwin -shared -o Crapo.src -S -I "C:\Program
Files\Java\jdk1.6.0\include" -I "C:\Program
Files\Java\jdk1.6.0\include\win32" Crapo.c
//remove @12 from Crapo.src
//run as -o Crapo.obj Crapo.src
//run ld -shared -o Crapo.dll Crapo.obj
//run nm Crapo.dll
U .bss
U .data
10001000 t .text
10001000 T _Java_Crapo_magicNumber
10001010 T __CTOR_LIST__
10001018 T __DTOR_LIST__
10002000 A __RUNTIME_PSEUDO_RELOC_LIST_END__
10002000 A __RUNTIME_PSEUDO_RELOC_LIST__
10001010 T ___CTOR_LIST__
10001018 T ___DTOR_LIST__
//... more crap
// by manually removing the @12 from the assembly source produced by
gcc and then separately assembling and linking solves the problem.
//I like the fact that their are far fewer unnecessary symbolic names.
Yet I was hoping their was a one step command-line option to be sent,
like --add-stdcall-alias? Any reason that doesn't seem to work for me?
//It's my understanding that -Wl,--add-stdcall-alias command-line
option is sent to the linker by gcc, and then subsequently sent to
dlltool where the option should result in the @nn's being removed from
the table of symbolic names. Is this correct?
- 15
- tomcatI just installed Tomcat 5.5 and went to http://127.0.0.1:8080/. Then I
clicked on Servlet Examples to see what examples it comes with, but I
got a 404 File not found error. Anyone know what the deal is? Are the
servlet examples separate?
|
|
|