windows authentication issue in runnable jar - java

I have created a project in eclipse. I am accessing a database using windows authentication from JDBC. I have sqljdbc_auth.dll in classPath. When I am running program from eclipse it is working fine but when I am creating runnable jar,most of the time JDBC is throwing exception that driver is not configured for windows authentication and a few times it connects. Anyone have any idea why is it happening?

With the high level details that you've provided, what I can think of right now are the following:
Check the run-time CLASSPATH of eclipse, then try to create a CLASSPATH" variable and add the same path.
Do not set a systemwide classpath. Either use a launcher script that correctly calls java -cp <the classpath> <everything else>, or in an executable file, use a MANIFEST.MF file with a Class-Path: header, or bundle all the needed classes into the JAR using the Maven shade plugin
Make sure your executable jar has the dependency in MANIFEST.MF for all the necessary jars (along with MainClass)
Hope that these details are helpful in an attempt to your problem.

Related

How to customize java options of a independent netbeans application?

i'm developing an application using Netbeans RCP. I have added an option to add a jar to my class path in the project.properties file of my platform:
run.args.extra=-cp:a ./appclient/glassfish/lib/gf-client.jar
The problem i encounter is that is does work when i run it from the Netbeans IDE but not when i try to create a independent application (build for Mac OSX for instance). I hear that the project.properties is no longer taken in account when you run an independent application and of course my appclient directory containing the jars does not exist anymore in the application package (so my jar is not added to class path).
How can i make this -cp option works for my independent Mac OSX application?
EDIT: i was able to create a custom conf file for my independent platform but i can't find a way to add my jar to the class path, i don't know what options to use.
EDIT: i found that i need to you endorsed mechanism to achieve it. So i have added the following command to my app.conf file:
J-Djava.endorsed.dirs=/Users/altanis/appclient/glassfish/lib/gf-client.jar
But when i run the .app (mac application), i get this error:
-J-Djava.endorsed.dirs=/Users/altanis/appclient/glassfish/lib/gf-client.jar: No such file or directory
The path is correct. Do i need to make something special to make the JVM aware of this? I followed this tutorial and somewhere in the comments the author says:
Right, but the package-appclient copies everything for you and you
should be able to put it on the classpath using the endorsed
mechanism. Unpack the jar created by that and add everything you need
from there (the jars) to your application installer. Then you can use
the endorsed (-J-Djava.endorsed.dirs=${GFCLIENT_PATH}) mechanism in
your app.conf to put it on the application classpath. This way you
should be able to deploy it together with your client.
I think, that create a new library is the better way.
Create module type library with required jars
In your module add dependency to created module (type wrapped library)
You must add entry Class-path to you application's MANIFEST.MF
For example
Class-Path: apache-commons-2.1.jar ejb-api-3.0.jar
all this jars should be in the root directory of your application
Your appliction should have next structure
MyApplication.jar
/META-INF
/META-INF/MANIFEST.MF
/apache-commons-2.1.jar
/ejb-api-3.0.jar
/com/package/classes
or you can use jar tool of JDK to create a jar
read more here Oracle doc

Java DB Derby and Netbeans 7.1 Build Problems

My application accesses a Derby Database and I have added the Derby.jar to the libraries in the project. It runs fine when compiled and runs perfectly inside the Netbeans environment but once I Build the project, only my application.jar file is in the dist folder. The program will still run but once I try doing anything with the database it hangs.
I tried adding the lib folder containing Derby.jar to the home directory of the application.jar but I still get the same problem.
I'm new to Derby and I'm confused by this, any suggestions?
The answer 1 above does not address the fact the you need to first connect to the database in the service tab of the IDE before you can run your application and that is not possible when you run your application outside the IDE.
This is because you don't also add the project external jar dependencies (such as Derby's jar) to the classpath of your project's executable jar. Basicly, try following their tutorial here:
http://netbeans.org/kb/articles/javase-deploy.html#Exercise_1
the chapter entitled "Running the Application Outside of the IDE" and the one after that.
I haven't used Netbeans in a long while so I don't know if they added this functionality to it now, but with Eclipse you can also make a "fat" executable jar, where all the external jars are packed inside that executable jar, and Eclipse adds a special classloader which makes all this work. It's the option called "Package required libraries into generated jar". Maybe Netbeans lets you do that now too, via some export function or something similar.

Having trouble exporting runnable JARs from Eclipse

Jar available at http://dl.dropbox.com/u/10919879/roller.jar
After writing and testing my program with Eclipse's built-in run Utilities, I decided it was time to export and distribute. So I go to File>Export>Runnable JAR and designate the class whose main method I want to invoke. Everything seems to be going off without a hitch, until I try to actually run the JAR.
Error: Could not find or load main class C:\Users\Matt\Documents\My Dropbox\Publ
ic\roller.jar
Contents of roller.jar
dice/Roller$RollData.class
dice/Roller.class
META-INF/MANIFEST.MF
contents of META-INF\MANIFEST.MF:
Manifest-Version: 1.0
Class-Path: .
Main-Class: dice.Roller
What's going on, and how do I fix it?
It's not a problem with your jar. It's a problem with OS setting that launches jar files incorrectly. I don't know if currently on Windows after installing Java it will be correctly configured automatically and why it isn't on your system. It may require editing registry to set jar files to be launched with java -jar command.
You can use application that converts JARs to EXEs if you're going to distribute it only to users with Windows.

Unable to run JAR file on another PC. Possible issue with Environment Variables?

I've built a JAR file and it executes fine on my PC (XP) which has Eclipse installed. It also works on another PC, which also has Eclipse.
I've tried running it on another PC(XP) that does not have Eclipse. Though it contains the JDK and multiple JRE. The JAR file just does not execute by clicking or from the command prompt.
I am not entirely sure, but my best guess is the Environment Variables are not set properly. Here is the error I receive from the command prompt:
Exception in thread "main" java.lang.NoClassDefFoundError: ...
Any help would be appreciated.
It must be a CLASSPATH issue.
The stacktrace should also say which class it failed to find. Once you have that, then find which jar has that class. Then add that jar file to your classpath or add it to the classpath env variable.
This is likely a classpath issue as others have said.
One thing to note is how your jar is constructed. You have a number of options in the dialog for exporting a runnable jar;
Extract classes into jar
Zip dependencies into the jar - creates jar-in-jar-loader.jar inside the jar.
Place jars in a subdirectory next to the jar.
Depending on what you have chosen for this depends on how the jar will behave. If the classes are extracted, dependent classes not in the JDK should be on the classpath. I'd recommend this course of action as it is simpler.
Now, the question is - are you using a dependency on your classpath not in the build dependencies of the eclipse project? If so, it won't be packed with / zipped into / put next to the jar because eclipse doesn't know about it (but java will still find it on your system because it's on the classpath). Also, if you've saved an ANT script and updated the build path in eclipse, eclipse won't update that ANT script - that is generated once only.
Environment variables are not considered when invoking a jar file when clicking on it (equivalent to running javaw -jar your.jar).
I'm pretty sure that it doesn't work on your first PC outside of Eclipse either.

Program stopped working after creating a .jar file with Netbeans

I made a simple Swing application with some database connectivity, using Notepad++ and executing it from the command prompt. It was executing perfectly.
Then I copied all of the code to Netbeans and tried to build to main project, in order to package my application as a .jar file.
A .jar file was created successfully, but when I tried to run it, it did not execute properly. For example, I had a button in my application that displays all records present in the database. It worked when I executed from the command prompt, but when the .jar file was executed, there was no response.
Hard to tell without seeing some code or error/exception stack traces. The most typical cause for problems of this kind are incomplete classpaths. Maybe your database driver class is missing on the classpath.
Some things you might check:
Do you get some sort of error?
Is the jar executable? If yes - that's the case when you start the application with something like java -jar path/to/myjar.jar - the classpath must be specified in the jar files Manifest, any -cp value is simply ignored.
Looking at your last comment, I'm pretty sure, that this is a classpath problem. The database driver usually resides in a different jar file and if the classpath entry in your manifest.mf file is blank, then the driver can't be loaded. This should result in an exception but maybe this is catched somewhere.
Solution #1 - edit the manifest.mf file and add all required libraries according to this tutorial:
Class-Path: jar1-name jar2-name directory-name/jar3-name
Solution #2 - don't start the application with the -jar option but use the standard way:
java -cp yourLib.jar;database-driver.jar your.application.Main
(all library entries have to be given with a correct relative or absolute file path)
just copy the database driver into C:\Program Files\Java\jre7\lib\ext and then run the jar file.

Categories

Resources