Alan Smith

Ranch Hand
+ Follow
since Oct 19, 2011
Alan likes ...
Netbeans IDE Firefox Browser Linux
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
3
Received in last 30 days
0
Total given
4
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Alan Smith

Hi,

no idea if this will help anyone but I downloaded Glassfish 4.1 and default user/pass is admin/<blank> i.e. there is no password.
8 years ago
Hi all,

Can someone please explain the above to me like I am a three year old? I have some example code below that draws a ball moving across the screen. Calling super.paint(g) clears the screen correctly before the ball gets repainted, super.repaint does not. So what is the difference between the two? Are they just poorly named methods?



I'm just trying to get into simple 2D game programming with Swing. Struggling with the basics already

Edit: to add to this, the javadoc for JPanels paint method states:
"Applications should not invoke <code>paint</code> directly, but should instead use the <code>repaint</code> method to schedule the component for redrawing."

Repaint does not work to correctly redraw the panel and the ball as seen in my example above, so I had to call super.paint.

Thanks
8 years ago
Hi all,

can someone give me a quick summary about java ear package types default classpath? For example:

If I have an ear file that contains numerous war files and jar files. Let's also say that each war file has a lib dir with some jars in it. Can all these jars/wars "see" each other by default when the ear file is launched? In other words, is every class accessible to one another as all of these classes go into the classpath when the ear is loaded?

Thanks

edit: further note, I am looking at an ear deployed on a jboss app server which is why I ask. There is a single ear with multiple web apps (wars), each web app has a lib dir with some jars, and there are also jars located in the ear files lib directory.
9 years ago
Hi,

I have a small task to loop over an array of xml elements and assign their attribute values to a simple class containing two strings and a boolean. What is the most efficient way to create new objects in this loop and add them to an array? I am using method 3 below, but is this the most efficient and why? Thanks.

Method 1:


or

Method 2:


or

Method 3:


Thanks
9 years ago

Tim Holloway wrote:
Thinking that you could just point to a directory full of JARs and have all the classes in all the JARs automatically available is one of the oldest newbie problems in the book.



Hi Tim,

the above seems to be correct...

For example, the below works:

java -cp "NonGFClient-1.0.jar:/home/alan/jars/*:/home/alan/programs/glassfish-4.1/glassfish/lib/gf-client.jar" com.alan.Main; where NonGFClient-1.0.jar is a standalone client that contains the main and a lookup of an EJB that is deployed on a local glassfish server. /home/alan/jars/* contains my remote interface, and the javaee jar that the client depends on. The gf-client.jar is a jar that all standalone clients that lookup EJBs on glassfish need.

ls /home/alan/jars/*
/home/alan/jars/javaee-api-7.0.jar /home/alan/jars/RemoteInterfaces-1.0.jar

Also, I have discovered that using -cp with the $CLASSPATH variable is pointless, as it completely ignores it by name. However, if I make another "CLASSPATH" variable called, for example, JARS, that works. e.g.

java -cp "NonGFClient-1.0.jar:$JARS/*:/home/alan/programs/glassfish-4.1/glassfish/lib/gf-client.jar" com.alan.Main

echo $JARS
/home/alan/jars

ls $JARS
javaee-api-7.0.jar RemoteInterfaces-1.0.jar

All in all, I'm still not sure of the correct way to utilise a classpath for an application that isn't packed as an ear or war, as they both can contain lib directories for their specific dependencies, and they can also utilise the app servers provided classpath for every else. Food for thought I guess.

Cheers
9 years ago

J. Kevin Robbins wrote:You shouldn't need to specify the full jar file name in either the environment variable or the -cp option, only the directory or directories where the jars are located.

Think of it like the $PATH environment variable in Windows or *nix. You don't specify the name of each executable file, only the directories where the executables are located.



Ok, thanks for the help.
9 years ago

J. Kevin Robbins wrote:I generally recommend that people avoid using the $CLASSPATH environment variable. It just leads to headaches like this. You should be able to specify the directory where your jar files are located like so:

javac -cp /home/alan/jars main



You can't combine the $CLASSPATH and the -cp option. When you use -cp or -classpath it takes precedence over the environment variable.



Assuming that the compile time environment can be different from the runtime environment, my client jar is already built using maven. If I want to run it elsewhere and bring the appropriate jars to run it with it, then I can't compile with javac.

If the environment variable is used i.e. I don't run java with -cp or -classpath, the same thing happens. It doesn't pick up the jars from the CLASSPATH env variable. The only way it has successfully found the jars is if I run it like I have stated above, with the full paths to each required jar. Is there no better approach than this?
9 years ago
Hi all,

Can someone explain to me how to correctly pass in classpath(s) to a java program using -cp or -classpath?

I put the required jars into a folder called /home/alan/jars:
ls /home/alan/jars
gf-client.jar RemoteInterfaces-1.0.jar

I was trying to use the $CLASSPATH variable which had my jars in it i.e.

echo $CLASSPATH
/home/alan/jars/gf-client.jar:/home/alan/jars/RemoteInterfaces-1.0.jar

Then ran java -cp RemoteClient-1.0.jar:$CLASSPATH com.alan.remoteclient.Main. (RemoteClient-1.0.jar contains my main method). This didn't work, and found out why here on stackoverflow.

Edit: When I do this however and add my client jar to the CLASSPATH, it manages to pick up the main method, but not the classes from the required jars in the $CLASSPATH!!
(So my classpath now looks like this:
echo $CLASSPATH
/home/alan/NetBeansProjects/RemoteClient/target/RemoteClient-1.0.jar:/home/alan/jars/RemoteInterfaces-1.0.jar:/home/alan/jars/gf-client.jar)
java -cp $CLASSPATH com.alan.remoteclient.Main
Hello World Remote Client!
Feb 03, 2015 2:49:36 PM com.alan.remoteclient.Main main
SEVERE: null
javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.enterprise.naming.SerialInitContextFactory [Root exception is java.lang.ClassNotFoundException: com.sun.enterprise.naming.SerialInitContextFactory]

How come it picked up the main from RemoteClient-1.0.jar in the CLASSPATH, but not the classes in the other jars??

Then I used java -cp "RemoteClient-1.0.jar:/home/alan/jars/*" com.alan.remoteclient.Main. This picked up the main but bombed when it tried to find classes in the required jars in /home/alan/jars. But according to this page, this should have worked.

The only way I have gotten it to work is if I pass every jar location to it directly i.e.

java -cp RemoteClient-1.0.jar:/home/alan/jars/gf-client.jar:/home/alan/jars/RemoteInterfaces-1.0.jar com.alan.remoteclient.Main
Hello World Remote Client!
Hello from SessionBean!

Any idea how to add multiple jars to the cp option without having to specify each individual jar with complete path?

Thanks

ps. the project is a small test of a stand alone client for a remote ejb that is deployed on glassfish. The com.alan.remoteclient.Main class looks up the bean and simply calls a hello() method from the bean that prints "Hello from SessionBean!".
9 years ago

Frits Walraven wrote:Hi Allan,

Did you read this Glassfish EJB FAQ?

Regards,
Frits



Hi Frits, no I have not! Thanks. I'll check this out.

Regards,
Alan
Still not working I have updated the manifest to point to a jar outside the jarfile but glassfish still isn't picking it up when I deploy the jar. I have the jar in every lib directory I can find in glassfish as well! Dunno what is going on at this stage.

Manifest:
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: alan
Build-Jdk: 1.7.0_45
Main-Class: com.alan.client.Main
Class-Path: /home/alan/jars/RemoteInterfaces-1.0.jar <- this contains a remote interface called SessionBeanRemote

Glassfish error on deployment:
SEVERE: Class [ Lcom/alan/SessionBeanRemote; ] not found. Error while loading [ class com.alan.client.Main]

Rob Spoor wrote:With that manifest, the JVM is looking for these JAR files in a folder called lib that is in the same folder as the main JAR file. It's not looking in a lib folder inside the main JAR file.



I did not know this! I guess I'm confusing jar, war and ear packaging! I believe you can do this in the latter two. I'll try that out. Thanks for the help.
Hi,

I am trying to deploy a really simple EJB app-client jar to glassfish but keep seeing the following error in regard to my jar file:

The following extensions or libraries are referenced from the manifest of C:\Users\asmith\AppData\Local\Temp\Client-18654884305939595801.0.jar but were not found where indicated: lib\RemoteInterfaces-1.0.jar lib\javaee-api-7.0.jar ; ignoring and continuing

My jar is set up as follows:

Client-1.0.jar ->
->META-INF
MANIFEST.MF
application-client.xml
sun-application-client.xml
->com.alan.client
Main.class
->lib
RemoteInterfaces-1.0.jar
javaee-api-7.0.jar

My MANIFEST.MF contains:
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: asmith
Build-Jdk: 1.8.0_25
Main-Class: com.alan.client.Main
Class-Path: lib/RemoteInterfaces-1.0.jar lib/javaee-api-7.0.jar

What is the issue? Any help appreciated.

edit: I've tried to indent the jar contents correctly but not sure how to do it! Hopefully you can understand it's content layout.
Hi,

I am trying to deploy a really simple EJB app-client jar to glassfish but keep seeing the following error in regard to my jar manifest file:

The following extensions or libraries are referenced from the manifest of C:\Users\asmith\AppData\Local\Temp\Client-18654884305939595801.0.jar but were not found where indicated: lib\RemoteInterfaces-1.0.jar lib\javaee-api-7.0.jar ; ignoring and continuing

My jar is set up as follows:

Client-1.0.jar ->
->META-INF
MANIFEST.MF
application-client.xml
sun-application-client.xml
->com.alan.client
Main.class
->lib
RemoteInterfaces-1.0.jar
javaee-api-7.0.jar

My MANIFEST.MF contains:
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: asmith
Build-Jdk: 1.8.0_25
Main-Class: com.alan.client.Main
Class-Path: lib/RemoteInterfaces-1.0.jar lib/javaee-api-7.0.jar

What is the issue? Any help appreciated.

edit: I've tried to indent the jar contents correctly but not sure how to do it! Hopefully you can understand it's content layout.
9 years ago