Runtime execution (JAR) cannot locate Java CLASSPATH and Connector J - java

before now, my application has always compiled and executed. I just do my compilation using
jar cvmf mainClass.txt starcoder.jar .class images/.gif images/*.jpg *.bat
I have a
**Windows 7 OS,
Java JDK jdk1.7.0_05,
JRE JRE7,
Connector J mysql-connector-java-3.1.14-bin,
Using a TextPad for development,
The runtime is on C:/Program Files/Java and Java_home**
This application from TextPad, it runs well with the CLASSPATH and executes fine.
The system compiles properly but my JAR file fails to execute
PROBLEM: It fails to find my CLASSPATH on runtine execution(which works perfectly on compile time) giving me this Error
c:\Program Files (x86)\Java\jdk1.7.0_05\bin>java -jar starcoder.jar
ClassNotFoundException: com.mysql.jdbc.Driver SQLException: No
suitable driver found for jdbc:mysql://localhost/starinv?user=r oot
Exception in thread "main" java.lang.NoClassDefFoundError:
javax/mail/MessagingE xception
at serialz.(serialz.java:96)
at serialz.main(serialz.java:240) Caused by: java.lang.ClassNotFoundException: javax.mail.MessagingException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinCla
ssLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(C
lassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 2 more
The CLASSPATH
.;C:\Program Files (x86)\Java\jre7\lib\ext\comm.jar;.;C:\Program Files
(x86)\Java\jre7\lib\ext\mysql-connector-java-3.1.14-bin.jar;.;C:\Program
Files (x86)\Java\jre7\lib\ext\jxl.jar;.;C:\Program Files
(x86)\Java\jre7\lib\ext\mailapi.jar;.;C:\Program Files
(x86)\Java\jre7\lib\ext\mail.jar;.;C:\Program Files
(x86)\Java\jre7\lib\ext\activation.jar;.;C:\Program Files
(x86)\Java\jre7\lib
My connector J file is in the right location but I get an error while executing my JAR file.
I need help to resolve this.
is the same for both my development and runtime environment.

Try calling like this:
java -cp .;"C:\Program Files (x86)\Java\jre7\lib\ext\comm.jar";"C:\Program Files (x86)\Java\jre7\lib\ext\mysql-connector-java-3.1.14-bin.jar";"C:\Program Files (x86)\Java\jre7\lib\ext\jxl.jar";"C:\Program Files (x86)\Java\jre7\lib\ext\mailapi.jar";"C:\Program Files (x86)\Java\jre7\lib\ext\mail.jar";"C:\Program Files (x86)\Java\jre7\lib\ext\activation.jar";"C:\Program Files (x86)\Java\jre7\lib" -jar starcoder.jar
Note that I removed your classpath's redundant "." entries and quoted each path.

Related

ClassNotFoundException found while loading classes from extension classloader using java

I am using processbuilder to run specific task in seperate JVM instance. i have two directory lib and conflictlib. lib directory i have added under classpath and conflictlib i have added in "java.ext.dirs" System property. `
here is my command:
java -Xmx64m -XX:+HeapDumpOnOutOfMemoryError -Dserver.home='/home/local/tomcat/webapps/ROOT/WEB-INF' -Djava.ext.dirs='/home/local/tomcat/webapps/ROOT/WEB-INF/conflictlib' -cp '/home/local/tomcat/webapps/ROOT/WEB-INF/lib' SubProcessClass
why i have added conflictlib in java.ext.dirs system property-
i have some conflict jar files(same jar with different version) in lib and conflictlib. Task i need to perform in subprocess, classes should be loaded from conflictlib directory. lib directory i have added under -cp which will be loaded by System class loader and conflictlib is loaded by extension classloader. since extension class loaded first. but I am getting ClassNotFoundException.
java.lang.NoClassDefFoundError: org/json/JSONArray
Caused by: java.lang.ClassNotFoundException: org.json.JSONArray
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
json-20140107.jar
present under conflictlib directory. its giving ClassNotFoundException. could someone check this. i am not able to understand where i am doing mistake.
thanks in advance.

java.lang.NoClassDefFoundError at Runtime: Need Class not on Classpath

I have tried several approaches as suggested on this website as well as several others to no avail.
-Running Angstrom embedded Linux, OpenJDK6, Shark VM.
File Structure
All .java and .jar files are stored in directory ./src
jarfiles: j1.jar j2.jar
Source code: Coder.java, WrapperClass.java
Compiling and Running
javac -cp j1.jar:j2.jar Coder.java WrapperClass.java
Successfully compiles, outputs Coder.class, WrapperClass.class, as well as several other files including Coder$1.class through Coder$6.class, as well as Coder$Main_thread.class and Coder$Progress_Bar_Thread.class, any insight onto what all these .class files are for?
Run attempts all terminate in java.lang.ClassNotFoundException.
~/coder/src: java Package.Coder
~/coder/src: java -cp jar1.jar:jar2.jar Package.Coder
~/coder: java ./src/Package.Coder
~/coder: java -cp jar1.jar:jar2.jar ./src/Package.Coder
Thank you very much for your help. I have run this on NetBeans and can verify that it's functional code, just a matter of getting it to run on Linux.
Stacktrace is:
Exception in thread "main" java.lang.NoClassDefFoundError: Package/Coder Caused by: java.lang.ClassNotFoundException: Package.Coder
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:334)
Could not find the main class: Package.Coder. Program will exit
Assuming this structure
/coder
/src
/Package
/Coder.java
/WrapperClass.java
/j1.jar
/j2.jar
You will need to compile from /src as
javac -cp j1.jar:j2.jar Package/Coder.java Package/WrapperClass.java
This will create .class files in /Package. You can then run it, again from /src as
java -cp j1.jar:j2.jar Package.Coder
assuming the Coder class has a main method which is your entry point.

Could not find the main class

I am trying to run a java program bundled in the jar named easyflow-gui.jar using cmd:
java -classpath "." -jar easyflow-gui.jar
The working directory is the directory containing all relevant libraries.
The content of the Manifest file of the jar file I am trying to run is:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.3
Created-By: 1.6.0_32-b27 (Sun Microsystems Inc.)
Main-Class: easyflow.custom.jgraphx.editor.SchemaEditor
The result of this attempt is:
Exception in thread "main" java.lang.NoClassDefFoundError: com/mxgraph/util/mxEventSource$mxIEventListener
Caused by: java.lang.ClassNotFoundException: com.mxgraph.util.mxEventSource$mxIEventListener
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: easyflow.custom.jgraphx.editor.SchemaEditor. Program will exit.
Question: which one of the classes is actually not found: the mxEventSource$mxIEventListener or the main class easyflow.custom.jgraphx.editor.SchemaEditor ?
Edit 1:
I checked the folder and extracted the jars and I find both classes available (bundled into its respective jars in the working dir):
$ls easyflow/custom/jgraphx/editor/SchemaEditor*
easyflow/custom/jgraphx/editor/SchemaEditor$1.class
easyflow/custom/jgraphx/editor/SchemaEditor$2.class
easyflow/custom/jgraphx/editor/SchemaEditor.class
easyflow/custom/jgraphx/editor/SchemaEditor.java
$ls com/mxgraph/util/mxEventSource*
com/mxgraph/util/mxEventSource$mxIEventListener.class
com/mxgraph/util/mxEventSource.class
You cannot specify "." for the classpath if you want to include a jar file, it has to be a colon-separated list of jar files or directories (or semicolon-separated, depending on the operating system). Try java -help to get a description of the command line options.
Also if I remember correctly -jar and -classpath do not work together, so you have to use -classpath alone and specify the main class explicitly.
Try something like
java -cp easyflow-gui.jar:foo.jar:bar.jar easyflow.custom.jgraphx.editor.SchemaEditor
... where foo.jar and bar.jar are the "other relevant libraries".
If you read the exception properly, you will see that the cause of the error:
Caused by: java.lang.ClassNotFoundException: com.mxgraph.util.mxEventSource$mxIEventListener
You didn't include the jar file that contains the com.mxgraph.util.mxEventSource$mxIEventListener in your classpath. From a quick Google search, you will need jGraph library.
I hope this helps.
The default classpath is the current working directory.
So, if you already have the jar in your current working directory, you dont need to specify the classpath explicitly.
The following command should work
java -jar easyflow-gui.jar

Java java server pages and netbeans

I have developed a .jsp website using NetBeans. It is working perfectly well when I run it from NetBeans but when I clean and build the project and copy the .war file from the dist folder and copy in the webapps folder of the TomCat 5.0 that is installed alongwith no .jsp file is being executed.
The error shows:
exception
org.apache.jasper.JasperException: Unable to compile class for JSP
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:97)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:346)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:414)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK
org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory.getCompiler(CompilerAdapterFactory.java:106)
org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:935)
org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:764)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:382)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
Sometimes while cleaning and building the project an error occurs in NetBeans that MySQL driver.jar i.e. included library cannot be deleted.
tomcat uses environment variable JAVA_HOME, set it to point to your jdk

How to correctly make a java jar file using this makefile with files in src/ and bin/

I am having trouble correctly generating a Jar for my Java implementation. I am not a Java master ( Thus why I am using Make and not Ant). I didn't think I cared about a Jar until I realized my Windows machine didn't hava javac. Then I thought to myself "If only I had a jar"
So I hacked a few lines together in a Makefile trying
The relevant lines are
all: client server jar
client: bin bin/Job.class bin/JobQueue.class bin/Client.class bin/FileTransfer.class
server: bin bin/Job.class bin/JobQueue.class bin/Server.class bin/ServerThread.class bin/FileTransfer.class
jar: client server
jar cfe HBNQServer Server bin/Server.class bin/Job.class bin/JobQueue.class bin/ServerThread.class bin/FileTransfer.class
jar cfe HBNQClient Client bin/Client.class bin/Job.class bin/JobQueue.class bin/FileTransfer.class
However when I attempt to run it I get a No Class Found Exception.
$ java -jar HBNQServer
Exception in thread "main" java.lang.NoClassDefFoundError: Server
Caused by: java.lang.ClassNotFoundException: Server
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)
I am sure the mistake is painfully obvious to anyone more familiar with "Jaring" files.
If I left any important code out, it may be found Here
I believe your problem is the bin prefix. If you jar a class file, it must be in a directory identical to its fully qualified package name. For example, if you implement a com.mycompany.Server class, the corresponding path in the jar file must be com/mycompany/Server.class. In your case, everything is in the bin directory in the jar file, so it can't find your (presumably un-package-qualified) classes. Either put all of your classes in the bin package, or jar them up without the bin prefix.
Something like this might work:
jar: client server
cd bin; jar cfe ../HBNQServer Server Server.class Job.class JobQueue.class ServerThread.class FileTransfer.class
cd bin; jar cfe ../HBNQClient Client Client.class Job.class JobQueue.class FileTransfer.class
You need a manifest for your JAR, as discussed here.

Categories

Resources