Classpath set, but: java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver - java

Okay, I'm confused. My SQL Server JAR is here:
Volume in drive C has no label.
Volume Serial Number is 8008-2D93
Directory of c:\temp
03/07/2014 09:38 AM <DIR> .
03/07/2014 09:38 AM <DIR> ..
03/05/2014 10:34 PM 222,417 output.exd
02/17/2012 02:45 PM 563,117 sqljdbc.jar
02/17/2012 02:45 PM 584,207 sqljdbc4.jar
3 File(s) 1,369,741 bytes
2 Dir(s) 21,865,553,920 bytes free
My Classpath is set:
C:\WINDOWS\system32>echo %CLASSPATH%
.;C:\Program Files (x86)\Java\jre7\lib\ext\QTJava.zip;c:\temp\sqljdbc4.jar
Its a JDBC 4.0 driver, so I shouldn't need to do this, but I've tried setting the class name.
Properties connectionProps = new Properties();
connectionProps.put("user", this.jdbcUser);
connectionProps.put("password", this.jdbcPass);
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn = DriverManager.getConnection(this.jdbcUrl, connectionProps);
Still I execute my program and I'm getting the error:
java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
C:\WINDOWS\system32>java -jar "C:\Users\MYUSER\Documents\NetBeansProjects\myappSource\dist\myappSource.jar" -u MYUSER -p MYPASS -j "jdbc:sqlserver://127.0.0.1\\msqlserver:1433;database=MYDB"
Mar 07, 2014 9:49:54 AM filters.myapp.dao.db.DbSwitcher getDatabaseForUrl
SEVERE: jdbc:sqlserver://127.0.0.1\\msqlserver:1433;database=MYDB
Mar 07, 2014 9:49:54 AM filters.myapp.dao.db.Database connect
SEVERE: null
java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at filters.myapp.dao.db.Database.connect(Database.java:217)
at filters.myapp.dao.db.Database.<init>(Database.java:38)
at filters.myapp.dao.db.MssqlDb.<init>(MssqlDb.java:15)
at filters.myapp.dao.db.DbSwitcher.getDatabaseForUrl(DbSwitcher.java:14)
at filters.myapp.UserInterface.cli(UserInterface.java:76)
at filters.myapp.UserInterface.<init>(UserInterface.java:34)
at filters.myapp.UserInterface.main(UserInterface.java:46)
In case it matters, I'm running Windows 8.1. I've tried the command prompt both as an admin and as not.
Java info:
C:\WINDOWS\system32>java -version
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)
Any ideas?
SQL Server is SQL Server Express 2012.

If you pass -jar to java.exe then the classpath is taken from the specified Jar file's manifest; all external classpath settings (e.g. %CLASSPATH%) are ignored.
Do one of:
Use java -cp ...\myapp.jar MainClassName
Put sqljdbc.jar into the Class-Path field in myapp.jar's manifest.
Discover and load sqljdbc.jar programmatically.

copy sqljdbc4.jar under WebContent-->WEB_INF -->lib folder.
This resolved my problem.

set the class path for sqljdbc4.jar
CLASSPATH= D:\sqljdbc_4.0.2206.100_enu\sqljdbc_4.0\enu\sqljdbc4.jar;
if you are eclipse user remove unnecessary .jar file sqljdbc

If you programme application ZK, then put sqljdbc4.jar in the folder WebContent -> WEB_INF -> lib .
Reference:
Anand's comment.

Open a new command prompt, and try with steps as below, its not good to work inside C:\WINDOWS\system32
The issue says the sqljdbc4.jar is not properly set in the classpath.
C:\Test
set classpath=%classpath%;.;c:\temp\sqljdbc4.jar
java -jar "C:\Users\MYUSER\Documents\NetBeansProjects\myappSource\dist\myappSource.jar" -u MYUSER -p MYPASS -j "jdbc:sqlserver://127.0.0.1\\msqlserver:1433;database=MYDB"

I got this error after updating my Eclipse STS, it turned out my server forgot all of its configuration info during the update. I had to set up the server's classpath and environment variables all over again and that fixed the issue.

Related

running the .jar file of jalview

I am trying to get Jalview [1] running on my windows 7 system. The standard installation works without error but when starting (the .exe file) it I get "Windows error 2 occured while loading the Java VM". As this error is quite general I tried then
C:\Program Files (x86)\Jalview>java -jar jalview.jar
which leads to:
Java version: 1.8.0_121
x86 Windows 7 6.1
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Layo
ut
at jalview.bin.Jalview.doMain(Jalview.java:210)
at jalview.bin.Jalview.main(Jalview.java:180)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Layout
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
any ideas what is going wrong?
Thx
Morpheus
[1] http://www.jalview.org/Download
This error "java.lang.NoClassDefFoundError" occurs when there is a class missing in your respective packages.
I suggest please check if the class "Layout" is present at path : org/apache/log4j
If not then its correct that you have some missing files/libraries of log4j in the classpath.
Please vote and mark the solution if useful.
Thanks!
First check that in C:\Program Files (x86)\Jalview\lib the library min-jabaws-client-*.jar exists.
To run it from command line
cd C:\Program Files (x86)\Jalview
java -cp jalview.jar;lib/* jalview.bin.Jalview

Include .jar-File in PHPJAVA Bridge

I try to load the "Tasks" from a .mpp-File.
If I get the current date by java.util.Date it works very fine, to access JAVA but if i try to access the MPPReader I get the error:
CreateInstance failed: new net.sf.mpxj.mpp.MPPReader. Cause: java.lang.ClassNotFoundException
This is the code to my test case.
define("JAVA_SERVLET", false);
define("JAVA_HOSTS", 9267);
$mpxjPath = getcwd()."/libs/java/mpxj-5.6.0.jar";
exec("java -cp $mpxjPath");
require_once("libs/java/Java.inc");
$date = new java('java.util.Date');
echo $date;
$project = new java('net.sf.mpxj.mpp.MPPReader');
This is the output in the browser
Wed Feb 01 08:53:43 CET 2017
Fatal error: Uncaught [[o:Exception]:"java.lang.Exception: CreateInstance failed: new net.sf.mpxj.mpp.MPPReader. Cause: java.lang.ClassNotFoundException: net.sf.mpxj.mpp.MPPReader VM: 1.7.0_55#http://java.oracle.com/" at:
#-15 java.net.URLClassLoader$1.run(URLClassLoader.java:366)
#-14 java.net.URLClassLoader$1.run(URLClassLoader.java:355)
...
The output shows, that the java is reachable. But how can I access the MPPReader ?
Update
Server: CentOS 7
This is the code in my index.php right now.
<?php
define("JAVA_HOSTS", 9267);
define("JAVA_SERVLET", false);
require_once("libs/java/Java.inc");
echo "<pre>";
$date = new java('java.util.Date');
echo $date;
$project = new java('net.sf.mpxj.mpp.MPPReader');
?>
Run Standalone command on CentOS 7
java -cp "ext/JavaBridge.jar:libs/java/mpxj-5.6.0.jar" php.java.bridge.Standalone SERVLET:9267
This is the error.
Thu Feb 02 07:11:45 CET 2017PHP Fatal error: Uncaught [[o:Exception]:"java.lang.Exception: CreateInstance failed: new java.net.sf.mpxj.mpp.MPPReader. Cause: java.lang.ClassNotFoundException: java.net.sf.mpxj.mpp.MPPReader VM: 1.7.0_55#http://java.oracle.com/" at:
#-15 java.net.URLClassLoader$1.run(URLClassLoader.java:366)
#-14 java.net.URLClassLoader$1.run(URLClassLoader.java:355)
#-13 java.security.AccessController.doPrivileged(Native Method)
#-12 java.net.URLClassLoader.findClass(URLClassLoader.java:354)
#-11 java.lang.ClassLoader.loadClass(ClassLoader.java:425)
#-10 sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
#-9 java.lang.ClassLoader.loadClass(ClassLoader.java:358)
#-8 java.lang.Class.forName0(Native Method)
#-7 java.lang.Class.forName(Class.java:270)
#-6 php.java.bridge.Util.classForName(Util.java:1518)
#-5 php.java.bridge.JavaBridge.CreateObject(JavaBridge.java:445)
#-4 php.java.bridge.Request.handleRequest(Request.java:458)
#-3 php.java.bridge.Request.handleRequests(Request.java:500)
#-2 php.java.bridge.http.ContextRunner.run(Co in http://127.0.0.1:9267/JavaBridge/java/Java.inc on line 195
Looking at your attempt to load the mpxj-5.6.0.jar, I noticed you tried to make it available to the JVM from the client side (PHP):
$mpxjPath = getcwd()."/libs/java/mpxj-5.6.0.jar";
exec("java -cp $mpxjPath");
require_once("libs/java/Java.inc");
The idea looks appealing, but sadly cannot work that way.
Remember the java-bridge is made of two parts, the client (Java.inc / PHP) and server (PHPJavaBridge / Generally a servlet). So if you want to add a library to the classpath, it must be done on the server side (available to the JVM).
From your code example (define("JAVA_SERVLET", false)), I assume you're not starting the bridge through Tomcat/servlet env, but with the standalone server. In this scenario, you'll have to add the *.jar on the classpath when starting the server.
You'll end up doing something approx like this to start the server :
$ java -cp "./JavaBridge.jar:/path/to/mpxj-5.6.0.jar" php.java.bridge.Standalone SERVLET:9267
edit: replace /path/to/ in by the correct location of the jar.
If you're working on Linux/Mac, have a look at the pjbserver-tools project. It provides a php-wrapper around the standalone server where you can easily configure deps.
Just keep aware of two things:
Servlet mode (.war/tomcat) is the way to go if you intend to use it in production. If you're unsure about how it works, see the pjb-starter-gradle which contains documentation.
The older Java.inc won't run on PHP7 and support won't probably be continued... At least take time to consider using the reworked client: soluble-japha. It might even be easier to work with it, but of course, as the author, I'm biased. Check for yourself ;)
Note for servlet tomcat:
For servlet tomcat install, same idea applies. Just make sure your .jar file(s) are present in WEB-INF\libdirectory. See also the unoffical php-java-bridge fork to get the latest .war template.

TomEE startup error: Cannot create unique file, please set java.io.tmpdir to a writable folder or create work folder

While starting up my application from within IntelliJ 14 the app server TomEE 7.0.62 gives following error message:
cannot create unique file, please set java.io.tmpdir to a writable folder or create work folder
at org.apache.openejb.assembler.DeployerEjb.<clinit>(DeployerEjb.java:109)
System:
OSX, IntelliJ 14, TomEE-Plume 7.0.62 (homebrew), Java 8 (homebrew cask)
Java version:
/usr/libexec/java_home -V
Matching Java Virtual Machines (1):
1.8.0_60, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home
Deployment: The basic Hello World sample app from Vaadin Framework 7
Infos:
TomEE startup over Terminal with startup.sh works ok, default tomcat welcome screen is shown on localhost:8080
Tried to add JVM option to set java.io.tmpdir to a different directory with chmod 777 privileges. VM options: -Djava.io.tmpdir=<new temp dir>
Tried to export env variable with export _JAVA_OPTIONS=-Djava.io.tmpdir=<new temp dir>
With Tomcat 8 hello world app works ok
Full error log:
java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.apache.openejb.util.Classes.forName(Classes.java:64)
at org.apache.openejb.config.rules.ValidationBase.loadClass(ValidationBase.java:151)
at org.apache.openejb.config.rules.CheckMethods.check_unusedCreateMethods(CheckMethods.java:318)
at org.apache.openejb.config.rules.CheckMethods.validate(CheckMethods.java:55)
at org.apache.openejb.config.rules.ValidationBase.validate(ValidationBase.java:50)
at org.apache.openejb.config.AppValidator.validate(AppValidator.java:101)
at org.apache.openejb.config.ValidateModules.deploy(ValidateModules.java:38)
at org.apache.openejb.config.ConfigurationFactory$Chain.deploy(ConfigurationFactory.java:403)
at org.apache.openejb.config.ConfigurationFactory.configureApplication(ConfigurationFactory.java:971)
at org.apache.openejb.config.ConfigurationFactory.getOpenEjbConfiguration(ConfigurationFactory.java:526)
at org.apache.openejb.config.ConfigurationFactory.getOpenEjbConfiguration(ConfigurationFactory.java:591)
at org.apache.openejb.assembler.classic.Assembler.getOpenEjbConfiguration(Assembler.java:459)
at org.apache.openejb.assembler.classic.Assembler.build(Assembler.java:438)
at org.apache.openejb.OpenEJB$Instance.<init>(OpenEJB.java:150)
at org.apache.openejb.OpenEJB.init(OpenEJB.java:298)
at org.apache.tomee.catalina.TomcatLoader.initialize(TomcatLoader.java:256)
at org.apache.tomee.catalina.ServerListener.install(ServerListener.java:168)
at org.apache.tomee.catalina.ServerListener.lifecycleEvent(ServerListener.java:55)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:402)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:110)
at org.apache.catalina.startup.Catalina.load(Catalina.java:638)
at org.apache.catalina.startup.Catalina.load(Catalina.java:663)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:280)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:454)
Caused by: org.apache.openejb.OpenEJBRuntimeException: cannot create unique file, please set java.io.tmpdir to a writable folder or create work folder
at org.apache.openejb.assembler.DeployerEjb.<clinit>(DeployerEjb.java:109)
... 32 more
Thank you all..
you can add openejb.system.apps=false in conf/system.properties or just export CATALINA_TMPDIR to a "new tmp dir value"

java.lang.UnsatisfiedLinkError: no jinput-linux, when running a my jar artifact

I'm having some issues with a java project in which I use a gamepad controller, thrustmaster firestorm dual analog 3 (usb), under ubuntu 12.04LTS. I know the controller works under ubuntu since I can calibrate and test it. The problem lies on running the jar since I get the following error:
un 04, 2013 9:39:42 AM net.java.games.input.ControllerEnvironment log
INFO: Failed to load library: no jinput-linux in java.library.path
java.lang.UnsatisfiedLinkError: no jinput-linux in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1856)
at java.lang.Runtime.loadLibrary0(Runtime.java:845)
at java.lang.System.loadLibrary(System.java:1084)
at net.java.games.input.LinuxEnvironmentPlugin$1.run(LinuxEnvironmentPlugin.java:69)
at java.security.AccessController.doPrivileged(Native Method)
at net.java.games.input.LinuxEnvironmentPlugin.loadLibrary(LinuxEnvironmentPlugin.java:61)
at net.java.games.input.LinuxEnvironmentPlugin.<clinit>(LinuxEnvironmentPlugin.java:102)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:188)
at net.java.games.input.DefaultControllerEnvironment.getControllers(DefaultControllerEnvironment.java:159)
at com.codeminders.ardrone.controllers.ThrustmasterController.initGamepad(ThrustmasterController.java:88)
at com.codeminders.ardrone.controllers.ThrustmasterController.getGamepad(ThrustmasterController.java:79)
at com.codeminders.controltower.ControlTower.initController(ControlTower.java:114)
at com.codeminders.controltower.ControlTower.<init>(ControlTower.java:90)
at com.codeminders.controltower.ControlTower.main(ControlTower.java:591)
Jun 04, 2013 9:39:42 AM net.java.games.input.ControllerEnvironment log
INFO: net.java.games.input.LinuxEnvironmentPlugin is not supported
No gamepad found!
No suitable controller found! Control disabled
Connecting to the drone
Using command port: 1500
I have created the .jar artifact with IDEA, and I think I have included all the libraries in the .jar, but even so, I get that error. I have also tried to execute my .jar like this
java -jar javadrone2.jar -Djava.library.path=/usr/li/libjinput.so
But with the same output... I believe that I have installed the jinput library, because if I type
:$ locate jni
...
/usr/lib/jni
/usr/lib/i386-linux-gnu/jni
/usr/lib/i386-linux-gnu/jni/libatk-wrapper.so
/usr/lib/i386-linux-gnu/jni/libatk-wrapper.so.0
/usr/lib/i386-linux-gnu/jni/libatk-wrapper.so.0.0.18
/usr/lib/i386-linux-gnu/jni/libgnomeproxy-1.0.0.so
/usr/lib/i386-linux-gnu/jni/libpty.so
/usr/lib/i386-linux-gnu/jni/libspawner.so
/usr/lib/jni/libjinput.so
/usr/lib/jni/liblwjgl.so
/usr/lib/jni/libswt-atk-gtk-3833.so
...
:$locate jniput
...
/usr/lib/jni/libjinput.so
/usr/share/java/jinput.jar
...
What can I do to run my .jar??

Issues when attempting to compile AspectJ tutorial application

I was trying to follow this tutorial:
http://andrewclement.blogspot.pt/2009/02/load-time-weaving-basics.html
but I stumbled across a couple of problems:
To start with, my system didn't have the javac and ajc PATH variables set, so I added the bin/ directory of my JDK7 to the PATH variable, as well as AspectJ's bin/ directory.
But when running ajc WhereDoesTheTimeGo.java Simple.java I got the following error:
[warning] couldn't find aspectjrt.jar on classpath, checked: C:\Program Files\Ja
va\jre7\lib\resources.jar;C:\Program Files\Java\jre7\lib\rt.jar;C:\Program Files
\Java\jre7\lib\sunrsasign.jar;C:\Program Files\Java\jre7\lib\jsse.jar;C:\Program
Files\Java\jre7\lib\jce.jar;C:\Program Files\Java\jre7\lib\charsets.jar;C:\Prog
ram Files\Java\jre7\lib\jfr.jar;C:\Program Files\Java\jre7\classes;C:\Program Fi
les\Java\jre7\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jre7\lib\ext\dn
sns.jar;C:\Program Files\Java\jre7\lib\ext\jaccess.jar;C:\Program Files\Java\jre
7\lib\ext\localedata.jar;C:\Program Files\Java\jre7\lib\ext\sunec.jar;C:\Program
Files\Java\jre7\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jre7\lib\ext\
sunmscapi.jar;C:\Program Files\Java\jre7\lib\ext\zipfs.jar;C:\Program Files\Java
\jre7\lib\tools.jar
[error] classpath error: unable to find org.aspectj.lang.JoinPoint (check that a
spectjrt.jar is in your classpath)
so I manually added the referred file to the classpath:
ajc -cp ajc -cp C:\aspectj1.7\lib\aspectjrt.jar Simple.java WhereDoesTheTimeGo.java
and then execution went apparently alright, being both .class files created.
But then...:
ajtests>java Simple
Exception in thread "main" java.lang.NoClassDefFoundError: org/aspectj/lang/Sign
ature
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.aspectj.lang.Signature
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 6 more
so I once again added AspectJ's jars to the classpath:
java -cp C:\aspectj1.7\lib\aspectjrt.jar;C:\aspectj1.7\lib\aspectjtools.jar;C:\aspectj1.7\lib\aspectjweaver.jar;C:\aspectj1.7\lib\org.aspectj.matcher.jar Simple
But that will only yield
Error: Could not find or load main class Simple
What's going wrong here? Why is this giving me so much pain than what the tutorials would make me believe I'd have to have?
EDIT
I've noticed I only have to write
aj -cp .;;C:\aspectj1.7\lib\aspectjweaver.jar Simple
and that will work. What I'm finding strange is that aspectjweaver.jar seems to be already being passed on by the aj script:
#echo off
REM This file generated by AspectJ installer
REM Created on Tue Apr 16 19:02:36 BST 2013 by top_secret
if "%JAVA_HOME%" == "" set JAVA_HOME=C:\Program Files\Java\jre7
if "%ASPECTJ_HOME%" == "" set ASPECTJ_HOME=c:\aspectj1.7
if exist "%JAVA_HOME%\bin\java.exe" goto haveJava
if exist "%JAVA_HOME%\bin\java.bat" goto haveJava
if exist "%JAVA_HOME%\bin\java" goto haveJava
echo java does not exist as %JAVA_HOME%\bin\java
echo please fix the JAVA_HOME environment variable
:haveJava
"%JAVA_HOME%\bin\java" -classpath "%ASPECTJ_HOME%\lib\aspectjweaver.jar" "-Djava.system.class.loader=org.aspectj.weaver.loadtime.WeavingURLClassLoader" "-Daj.class.path=%ASPECTPATH%;%CLASSPATH%" "-Daj.aspect.path=%ASPECTPATH%" %*
Any clue?
Try this instead, for your java command:
java -cp .;C:\aspectj1.7\lib\aspectjrt.jar;C:\aspectj1.7\lib\aspectjtools.jar;C:\aspectj1.7\lib\aspectjweaver.jar;C:\aspectj1.7\lib\org.aspectj.matcher.jar Simple
You need to include the current directory (where you are compiling your source files to) in the classpath.

Categories