Philip Jenson

Greenhorn
+ Follow
since Jan 24, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Philip Jenson

My current method seems to work best, but I'm still very interested to hear what you guys have to say.

What I did was move the activemq-all-5.2.0.jar file into the jdk1.6.0_21\jre\lib\ext directory.

Doing that and having the JNDI file in the current directory (with my system CLASSPATH variable set to .) works.
13 years ago
I just got it to work! I'm very happy that it's working, but I'm hoping someone can clarify why it works now so I can learn something out of this.

I used this argument on the javac/java commands:
-cp "<source files location>;C:\Program Files\Apache Software Foundation\apache-activemq-5.2.0\activemq-all-5.2.0.jar"

I don't understand why that worked but putting the . there did not work. In the future, what would be the best way to do something like this? Let's assume my CLASSPATH environment variable is set to . and nothing else. I want to compile and run a program that depends on the activemq-all-5.2.0.jar file. Using the -cp argument seems like it adds confusion, so is there an easier way? I'm thinking I should be able have java use the environment variable CLASSPATH in addition to something I specify.

What do you guys think? Is there a different approach that's all-around easier?
13 years ago
Well, I have a jndi.properties file in the same location as the source code. Based on the errors I'm getting, it seems to me that it's not even getting far enough to read that file, though. Is that correct or could this potentially be part of the problem?
13 years ago
I'm assuming I don't have to add the . to the -cp argument, right? I'm grasping for straws, so I tried that, even though it seems redundant since I added the . to the the system CLASSPATH. Or does the -cp argument override the system-set CLASSPATH? Either way, I tried adding the . to the -cp argument.

java -cp ".;C:\Program Files\Apache Software Foundation\apache-activemq-5.2.0\activemq-all-5.2.0.jar" Chat TopicCF topic1 Fred

Gives me this error:

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an
applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at Chat.<init>(Chat.java:19)
at Chat.main(Chat.java:81)

At this point, I don't care what I need to do to get this running. The book just says "simply include the activemq-all-5.2.0.jar file in your classpath). It makes it seem so simple, so I feel like I have to be missing something. Based on what I've provided in this thread, is there an obvious reason that I'm having these problems?
13 years ago
David, I ran the following command in an effort to do what you said:
java -cp "C:\Program Files\Apache Software Foundation\apache-activemq-5.2.0\activemq-all-5.2.0.jar" Chat TopicCF topic1 Fred

Is that what you meant? In any case, I get the same exception:

Exception in thread "main" java.lang.NoClassDefFoundError: Chat
Caused by: java.lang.ClassNotFoundException: Chat
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: Chat. Program will exit.


Campbell, are you suggesting I add . to my environment variable CLASSPATH or to the javac/java commands? I do have a system CLASSPATH variable but the only thing in it was a specific entry for an unrelated application. I changed it so that it contains the period and nothing else. Before ever creating this thread, I set the ActiveMQ jar in my system CLASSPATH. I had the exact problems I'm having now, except then I didn't have to add the -cp arguments.
13 years ago
Greetings,

I am trying to work through a sample JMS application from the O'Reilly book Java Message Service (2nd edition). The code from the book is posted at the bottom of this post.

The sample Chat program is very simple. The book mentions that I need to add activemq-all-5.2.0.jar to my classpath. So I used the following command to build the program:

javac -cp "C:\Program Files\Apache Software Foundation\apache-activemq-5.2.0\activemq-all-5.2.0.jar" Chat.java

This works. The class file gets created successfully. However, when I try to run the program, I get an exception. The command I am using to run it is this:

java Chat TopicCF topic1 Fred

Exception in thread "main" java.lang.NoClassDefFoundError: Chat
Caused by: java.lang.ClassNotFoundException: Chat
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: Chat. Program will exit.

I've literally tried everything that I can think of. I thought maybe it was happening because of the package declaration but I don't think that's it. I've confirmed the directory structure is correct and even removed the package declaration altogether. I've searched endlessly for answers online but I can't seem to get past this.

If anyone could take a look at this, I would appreciate it greatly. I want to continue reading through this book but I've hit a roadblock that I can't seem to get past. Thanks!
13 years ago
This is my code so far, though I'm still working on it. I think I have the looping correct, but I'm having an awful time figuring out the destination position and number of elements for the arraycopy. I think I might have got the first one right, but I'm confused with the other two. I made the two lines giving me trouble bold and put question marks in the parameters that are giving me the most trouble.

I'm going to keep at it, but I'll check back to see if anyone understands what I'm having trouble with.


17 years ago
Pete,

That's a good idea. Also, I see what you mean about my loop. I'm not sure why I even thought that would work.

As far as saving the locations of the values into temp variables, how do I go about searching the array? Do I simply loop through the array and create an if statement to find the variables? I thought about using binarySearch, but I read that it must be sorted beforehand, which isn't possible for what I'm doing.

Is there an easier way to do this? I'm thinking that there must be.

Thanks.
17 years ago
Joanne,

Thanks for the tip. That makes a lot more sense than what I was going to try. I tried doing that only for the first part, which is when I need to put all of the cards before 49 or 50 at the end of the array. What I have below only does that and does not copy it back to the original array yet.

For what I am trying to do, does that look right? For some reason, it's giving me ArrayIndexOutOfBoundsException.



Like I said, all the above function has to do at this point is find either 49 or 50 and move all cards before it (but not including it) to the end of the temporary array.

I feel like there's probably a more elegant way of finding where the first instance of either 49 or 50 is.

Any suggestions would be great. Thanks.
17 years ago
I have an array of exactly 50 integers. I need to search through the array until I find a value of either 49 or 50. As soon as one of these values is found, I want to export all of the values that came before to their own array.

Next, I want to go through the original array until the other value is found (i.e. if 50 was found before, go through array until 49 is found). I then want to export all of these values (starting with either 49 or 50 and ending with the other) to their own array.

Finally, I want to export the remaining values in the original array to their own array. Then, I want to concatenate all of these arrays. The last array will come first, the second will stay in the middle position, and the first one will come last.

Now, I have written a lot of code to do this, but I have ran into a lot of problems. First, I don't know how large to make the arrays. I think I can solve this by using an ArrayList, which I have used once before. But my main problem is being able to search through the array at the correct location. As I said before, I want the first exported array to stop as soon as either 49 or 50 is found. But I'm having trouble getting the next search to begin where the last one left off. Should I use the indexOf method to save where the value was found and then begin searching there?

I've done some research to figure out the best way to add these three arrays together, but I can't find any consistency. Should I use the arraycopy method or is there an easier way to do this?

Thanks a million. Any help is appreciated.
17 years ago
I constantly have to access the command prompt to execute a particular command. The command is always the same except for one parameter, which is in the middle of the command. I started writing a batch file that would prompt me for the one parameter and execute the command.

However, I thought it would be pretty easy to write a Java program that would prompt for the the parameter and execute the command in the Windows command prompt. I thought that maybe the Java program would have to call the batch file, but I don't think this would be preferable. For one, I'm not sure if the Java program can accept an input and then pass said input to a batch file.

Would this be a good idea for a quick Java program or would it be a better idea to write a program like this in a different language? I'm taking a Java class now, but I have no idea how to execute commands in the Windows command prompt from Java.

Let me know what you think. Thanks!
17 years ago
Hello everyone.
This is the second time I've came here with a specific question. Everyone was great last time - I learned so much in the process. This time, my question is quite simple.

Basically, I am inputting an integer. The integer needs to be transformed into a "hexcode." In this example, 525 is input. It needs to be turned into 0D (525 % 16 % 16). However, it is output as DD. No matter what number I put in, the first and second digits are the same.

This is the process I am going for:
An integer % 16 -> Result (we'll call it code1) is sent to toHexDigit, where appropriate digit is returned (hex1).
Now, code1 % 16. This result (code2) is sent to toHexDigit, where appropriate digit is returned (hex2).
After that, I want to assign both of the returned digits (hex1 % hex2) to a variable, called code.

I've written the whole process out on paper and debugged it several times. I'm missing something, apparently. It seems that the integrity of one of the values is lost at some point. If anyone has any tips, please let me know. I've been staring at this for a long time with no improvement.

Thanks a million,
Philip






17 years ago
I was told to write a small program that finds the floor of logb(X). I took the main functionality of the program to create what I pasted below. In the program I have below, the base and x-value are already there - it's just for the concept.

I was told to use nested loops. However, I feel that the way I did it is fine. Would it be better if I used a nested loop? I'm not sure I would know exactly how to go about doing it, thought I'm sure there are a lot of ways to do it.

Thanks.

17 years ago
There's only one thing confusing me. No matter what I input to the program, d = 2�0s6p is returned from the read() function. I'm scratching my head right now at this...
17 years ago
marc,

That did the trick! Thanks a lot...I thought it was going to be much more difficult than that.
17 years ago