Win a copy of Classic Computer Science Problems in Swift this week in the iOS forum!

Zachary Anderson

Ranch Hand
+ Follow
since Oct 14, 2005
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Zachary Anderson

Found it! Inspired by Joanne Neal's brains on another question:
That problem was because my main class (part of a package) was at Game.jar/main.class rather than Game.jar/package/main.class.

I extrapolated that it might also be having problems finding pieces of the comm.jar because I hadn't unpacked it to Game.jar/javax/comm/(comm class files). Doing so, and re-jarring it with that directory structure, made the game able to find the remote device outside of the IDE.

I'm not sure what changed in JDeveloper's deployment options such that it doesn't seem to be including comm.jar, but as long as manual manipulation results in a working product, I'm happy .
In the meantime, I'll poke at JDeveloper a bit to see if I can get it to start including required .jars as well, so I won't have to remember to paste in these classes next time.
For more happy results, another (less-important, but still useful) function dependent on an external .jar stopped working a while back, and it stands to reason that this could be the same cause.

Off to smash more bugs!
Ah, excuse me all to pieces; the headbanging was meant to indicate frustration at my own ignorance. I really am grateful for Ms. Neal's brains!
7 years ago
Blast! J. Neal identified it correctly, I forgot about directory structure. I now have an executable .jar.
Thank you!

... now to hunt down the other bugs floating around...
7 years ago
Difficulty being, it's not in any of the traditional places.

The first line of is "package mycompany;"
I have created a jar containing all the classes of mycompany in "Game.version.jar".
The jar's manifest includes the line "Main-Class:", and is followed by two blank lines.
The jar includes game.class.

And yet,
java -jar Game.version.jar
Exception in thread "main" java.lang.NoClassDefFoundError: mycompany/game
Caused by:
... ClassNotFoundException and various Loaders.
Could not find the main class: Program will exit.

What am I missing? I'm not sure whether it's an improperly-constructed .jar, a naming problem, a classpath problem, or something completely different.
I'll keep reading up on executable .jars, but if you have a thought in the meantime I'd love to read it.
7 years ago
Ah, that makes sense. Yes, I should implement good practice in general, and do want the .jars to play nicely on other people's machines.

Thanks again!
7 years ago
Hello Mr. Johnson,
a and b: I wasn't aware of the " " and "\" issues. Thanks for the brains, will copy everything over to a C:/GameProject (or somesuch) folder and alter references appropriate to such.
c: Right now, because I only have the source directory named in one place in a very small build file, it's shorter to list it explicitly (and having it on a lower rung will make it shorter still). If I use a reference three or more times, (maybe two if it was complicated,) it makes more sense to me to have it as such. Is there a reason other than style to do so?
d: Will check out Maven.
Thanks again,
Zachary Anderson
7 years ago
Found it, it did, indeed need to be part of a larger file.

Of course, now the .jar can't find its main-class attribute, but as per my "Programmer's definition of progress: A new error message."
7 years ago
Silly smileys: That emoticon should be translated to a colon followed by a lowercase "o".
7 years ago
Hello JavaRanch,
. At Mr. Holloway's suggestion, I've started delving into Ant. Successful installation, "Ant -version" tells me its version and date!
. At first I had a smidge of trouble with writing "Build.xml", but I realized that WordPad was adding unseen characters and have switched to notepad (yes, I'm on a Windows machine, XP if it matters).
. This is the complete content of my Build.xml:

Typing "ant" on the command line results in the following output:
Buildfile: C:\Documents and Settings\zanders\build.xml

C:\Documents and Settings\zanders\build.xml:3: Unexpected element "{}jar" {}jar

Total time: 0 seconds.

. Because it says it's breaking on line 3, which is the end of the file, I expect there are other elements it wants to see along with the <jar> block. However, this is almost identical to their sample simple jar build. Did I miss a part where it said, "You have to add this to these other lines in the build file", or "every build file has to start with X"?
. An other consideration that might be important is that I'm using the java.class files constructed by an IDE (JDeveloper, if it matters). There's some oddity in that there are more .class files in that folder than I started with, i.e. I wrote "" and the class folder contains "moduleA.class" and "moduleA$randomOrganization.class", and I don't ever remember writing something called "" but there's a "Huffman.class". Would you recommend I use Ant to classify my java code as well? (It would be an ugly process, as there are dozens of files, but I think I can figure it out.)
. I will, of course, be reading on my own to solve this problem (as well as the problem of "I haven't formally studied this stuff in a decade"), but I'd appreciate any non-null pointers you're willing to lend.
Thanks for your brains,
Zachary Anderson
7 years ago
Oh dear... I probably qualify as a cheap labor hacker at this point. When last I did my own canning, dinosaurs ruled the earth, and I definitely haven't been staying in touch with the language.

I'll re-familiarize myself with the jar process and try it out tomorrow morning. Thanks for the brains!
Hello JavaRanch,
This is a case of not quite knowing enough to know what I don't know. I'll also be reading the oracle descriptions about imports and .jars, but it's rather dense and most of it doesn't seem applicable, so I thought multitasking would be a good answer; I can put this here and hope human expertise is able to direct me more rapidly than my scrolling through dry webpages in search of wisdom. I will, of course, still be reading up in the meantime; obviously I need to learn this stuff.
I'm using JDeveloper This code has gone through three iterations, environments, and programmers; I'm not sure whether that's pertinent, but just in case...
I'm making a small game. One of the parameters one can set in the starting screen is to operate a remote device (through an ADU card) whenever one scores.
It uses the javax.comm package to do so. In project properties in JDeveloper, I have comm.jar set to import, and when I dissect Game.jar, it contains comm.jar.
It runs fine as far as the first screen of the program, in which one selects program variables.
However, if I select the remote device to operate, and click "Start" to advance to the game, it doesn't respond. Not a hard crash, because I can still change variables, and even set the remote device to "off" and it will advance to the game. For further confusion, when I run it from within the JDeveloper environment, it will run with the remote device selected and the game runs fine and the remote device turns on.
Running java -jar Game.jar from the command line, when I select remote device and hit start, it throws the following error message:
... and about 50 more lines.
I've tried putting copies of comm.jar in the JRE's bin and lib folders where I hoped it would see it, I've checked to make sure it's inside Game.jar, I'm just... baffled. My intuition is that JDeveloper somehow isn't including comm.jar correctly in Game.jar, but I still don't know enough to be sure.
What else do you need? Where should I look?

And a less urgent additional question:
The program also uses two .dlls to operate. We've been dropping copies of them into Program Files/Java/jre(whatever the latest is)/bin every time we bring the jar to a new computer, which is semi-acceptable, but I was wondering if there's a way to bundle them within the .jar such that it would see them and I wouldn't have to instruct the user where to put the .dlls. For one thing, there's a small level of confusion since the jre doesn't always have the same number or location. For the second, the users sometimes get confused or lie about whether they've put the .dlls in the right place.

Happy Saint Patrick's Day!

dariyoosh za: I'm not running a web application, so I'm not sure I understand your question. This is going to be distributed by passing around .jars.
Jan Cumps: Unfortunately, forName() throws an exception, and demands that it be caught.
Jan Cumps,
I am indeed running it from JDeveloper. The first line in the "log window" (same place I get the results of my dummyprint statements) looks to be the call that JDeveloper makes to javaw.

I have switched out the previous getConnection statement with

and am getting
SQLException: No suitable driver found for jdbc:mysql://

Am absolutely sure of, have compared it with the (successful) login with SQLYog.

As a bit of a head-check ( ) after reading up on DriverManager, I decided to see what Drivers were actually in the list.
I tried the code at , but it looks like they have a bit of a mistake; since e is instantiated inside the start condition, it's not recognized in the body of the loop. Although that might be a JDeveloper mistake.

Anyways, running
gives me just
Does this mean I'm missing the driver I loaded, or is that a different name for it, or does the for-loop code miss the first item in the Enumeration?

Thanks again,
Jan Cumps,
The first line when I tell it to run is,

C:\Oracle\Middleware\jdk160_05\bin\javaw.exe -client -classpath "C:\JDeveloper\mywork\myprogram\Project1\classes;C:\Documents and Settings\zanders\My Documents\myprogram 2.X\comm.jar;C:\Documents and Settings\zanders\My Documents\Project Program\driver\mysql-connector-java-5.1.7\mysql-connector-java-5.1.7-bin.jar" mywork.y

Given that "C:\Documents and Settings\zanders\My Documents\Project Program\driver\mysql-connector-java-5.1.7\mysql-connector-java-5.1.7-bin.jar" is part of that, it looks to me like it's in the runpath as well. Am I interpreting that correctly?

Thank you for the suggestion about newInstance, I have now removed it. I threw it in after reading on about
// The newInstance() call is a work around for some
// broken Java implementations

Thanks for your brains,
Would anyone be willing to suggest how to test this code? I'm not really sure for what DriverManager is looking.

Running JDeveloper, have included mysql-connector-java-5.1.7-bin.jar in the "libraries and classpath" window.

spits out
SQLException: No suitable driver found for jdbc:mysql://host/database
SQLState: 08001
VendorError: 0

The fact that I'm no longer getting a "Class strife" message gives me the impression that it has successfully found the Driver. I am able to connect to the database with SQLYog, so I think the database has no problems.

I'm planning on putting this on several computers, so putting it into .lib folders might be possible, but not ideal.