Saxon 9.4 Query from cygwin - java

I am in the folder :
/cygdrive/d/ragsxq where I have kept some simple X-Query stmts to be executed via Saxon X-Query engine...(Saxon 9.4 HE )
The following statement :
$ java -classpath /cygdrive/d/saxon/saxon9he.jar net.sf.saxon.Query -q:ragsXQuery.xq
gives :
java.lang.NoClassDefFoundError: net/sf/saxon/Query Caused by:
java.lang.ClassNotFoundException: net.sf.saxon.Query 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) Could not find the main class:
net.sf.saxon.Query. Program will exit. Exception in thread "main"
But the below statement works fine:
$ java -classpath ../saxon/saxon9he.jar net.sf.saxon.Query -q:ragsXQuery.xq
?!?!
Something to do with the Class-loader..?? Permmissions..?? Cygwin ? Hmmmmm...
Thanks a lot for pointing out this Cygwin behavior!
But the strange thing is, i run into this java.lang.NoClassDefFoundError (exactly the same as above) when I try to Run an Xquery via my Eclipse (Indigo) on Mac OS Lion too...via the XQDT plugin, where I have to configure the XQuery engine by providing the full-path of the saxon9he.jar & the main-class viz., net.sf.saxon.Query
Note that a similar set-up on Windows-XP works fine.
This time, I guess it could be some Classpath issue or the way Mac OS's Java treats things differently ?

I think I have faced this before. It is probably a Cygwin nuance. Just try
$ java -classpath `cygpath -m /cygdrive/d/saxon/saxon9he.jar` net.sf.saxon.Query -q:ragsXQuery.xq
Here is a possible explanation as to why:
http://cygwin.com/ml/cygwin/2008-01/msg00083.html
Below is the output from my Cygwin for an executable JAR file. I use Windows Vista 32 bit (I know, it sucks).
adarshr$ java -jar /cygdrive/d/adarshr/data/cf.jar
Error: Unable to access jarfile /cygdrive/d/adarshr/data/cf.jar
adarshr$
adarshr$ java -jar `cygpath -m /cygdrive/d/adarshr/data/cf.jar`
Usage: java -jar cf.jar SEARCH [DIRECTORY] [OPTIONS]...
Try -h or --help for more information
As you can see, the second command worked and printed a help (as expected).

Related

Problem accessing one jar file from another

I've written a Java program that uses classes from the Apache PDFBox jar application. I have my compiled classes and the PDFBox jar file in on directory. I can run this successfully:
java -cp .;pdfbox-app.jar Athena NPCGenerator -pdf
However, when I jar up my own program and try to run it in the same place in a similar fashion, this fails:
java -cp .;pdfbox-app.jar -jar Athena.jar NPCGenerator -pdf
Error message:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/pdfbox/pdm
odel/PDDocument
at CharacterPDF.writePDF(CharacterPDF.java:49)
at NPCGenerator.printToPDF(NPCGenerator.java:302)
at NPCGenerator.makeAllNPCs(NPCGenerator.java:278)
at NPCGenerator.main(NPCGenerator.java:316)
at Athena.runApp(Athena.java:88)
at Athena.main(Athena.java:104)
Caused by: java.lang.ClassNotFoundException: org.apache.pdfbox.pdmodel.PDDocumen
t
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
What do I need to do to fix this?
If you use the -jar flag to java it expects a executable jar. It will then ignore the classpath on the command line and read the classpath from the jars manifest.
You can either add pdfbox-app.jar to the manifest in Athena.jar together with the main-class attribute. You can even specify a relative or absolute path to the jar in the manifest.
Main-Class: Athena
Class-Path: pdfbox-app.jar
Or you can not use -jar and add Athena.jar to your classpath via the command line. In this case you need to also specify the main class on the command line as java will not read the manifest in this case.
java -cp .;pdfbox-app.jar;Athena.jar Athena NPCGenerator -pdf

Lauch Eclipse SWT window application from command line error

First off. I am a newbie and green with respect to Java programming.
I created a Java Eclipse "SWT" "Application Window" on a Eclipse Kepler 4.3.1 (32-bit) running WindowBuilder and SWT (swt.jar). The design view is a composite.
The java application runs fine from Eclipse. I simply press the play button and presto.
Problem:
Issuing
java -cp . PkgNetAccelerator32.netAcceleratorApp
yields the following error message:
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/widgets/Composite
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.eclipse.swt.widgets.Composite
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
I was doing some research and several posts on other issues suggested that the cure is to create a manifest. I saw an article that said something like:
Select the src folder, right click and select export, then Java, then JAR file, specify Manifest.jar and a path on the folder, make sure the "Generate the manifest file" is selected, and press finish.
I created the manifest file and tried launching it with the following command line:
java -jar ../Manifest.jar -cp . PkgNetAccelerator32.netAcceleratorApp
That yielded the same error message above.
I saw another article that said that one should add in the swt.jar file, but that is taken care of by the manifest. No? Specifying "swt.jar" instead of the manifest that I created resulted in an error message:
no main manifest attribute, in ../swt.jar
That error message makes sense.
I am at a loss. How do I run the java application?
I am testing on my Windows 7 Professional 64-bit desktop, but I need to run on CENTOS too. That should be no problem, as I assume whatever the fix on Windows is, will work on CENTOS.
UPDATE:
I placed the two lib files in a /lib folder to match the answer given. I then issued the following command line and got the following error message.
C:\SoftDev\Projects\NetAccelerator\JavaWorkspace\NetAccelerator32>java -cp "bin/*;lib/*" PkgNetAccelerator32.netAcceleratorApp
Exception in thread "main" java.lang.UnsatisfiedLinkError: Cannot load 32-bit SWT libraries on 64-bit JVM
at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
at org.eclipse.swt.internal.C.<clinit>(Unknown Source)
at org.eclipse.swt.widgets.Display.<clinit>(Unknown Source)
at PkgNetAccelerator32.netAcceleratorApp.open(netAcceleratorApp.java:43)
at PkgNetAccelerator32.netAcceleratorApp.main(netAcceleratorApp.java:33)
I found the following article, which produces a command line that works, just that is not reasonable for sending. I much rather use the answer.
Lets assume you have a eclipse project structure similar to this:
Workspace
-> Project
-> src (source code directory)
-> bin (compiled byte code directory as JAR)
-> lib (jar directory)
-> .classpath (eclipse file)
-> .project (eclipse file)
I am assuming that you are exporting the JAR as an executable JAR.
So in order to run a class in that exported JAR with another JAR from the lib directory (swt.jar) while your working directory is the Project directory you will need to execute:
java -cp "bin/*:lib/*" PkgNetAccelerator32.netAcceleratorApp
Using wildcards requires Java 6 or later
Please note: CENTOS requires : as a path separator. Windows uses a semi-colon.
This will add your classes and the swt classes onto the classpath and run your main class PkgNetAccelerator32.netAcceleratorApp
SWT 32bit vs 64bit
You will either need to use a 32bit JVM locally or continue to use a 64bit JVM and use the 64bit version of swt; see swt on windows 64 bit. I would suggest you match your version of your local JVM (32bit or 64bit) with the version that you will be running on the CENTOS machine. You will however need a different swt jar for CENTOS.

NoClassDefFoundError org/eclipse/swt/SWTError

I m trying to compile an open source software . The build works fine and results into a jar file "five-server.jar". When I try to run this file from cmd , I get these errors.
C:\Users\vickey\code\five-server\dist\main>java -jar five-server.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/SWTError
Caused by: java.lang.ClassNotFoundException: org.eclipse.swt.SWTError
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)
Could not find the main class: org.devtcg.five.Main. Program will exit.
any suggestion what is wrong?
The SWT Jar files are platform dependent.
See http://www.jarfinder.com/index.php/java/info/org.eclipse.swt.SWTError
e.g. on Windows a suitable jar would be:
org.eclipse.swt.win32.win32.x86_3.1.0.jar
or on Mac OS X:
swt-macosx-3.0m7.jar
and so on.
You might run into call kinds of followup problems if you add this dependency e.g. whether you are
using 32bit or 64bit libraries.
It is too bad that these kind of dependency problems show up more often than not these days :-(
You have to set the classpath so that it includes at least the class org.eclipse.swt.SWTError
or the jar containing it:
java -classpath path/to/jar/containing/org.eclipse.swt.SWTError -jar five-server.jar
You should also set the Main-class attribute in the manifest file in the five-server.jar
Following the #Wolfgang Fahl answer, you might download the references here:
Standard Widget Toolkit » 4.3 x86
Maven reference:
https://mvnrepository.com/artifact/org.eclipse.swt.org.eclipse.swt.win32.win32.x86.4.3.swt/org.eclipse.swt.win32.win32.x86/4.3
Jar file:
http://central.maven.org/maven2/org/eclipse/swt/org/eclipse/swt/win32/win32/x86_64/4/3/swt/org.eclipse.swt.win32.win32.x86_64/4.3/org.eclipse.swt.win32.win32.x86_64-4.3.jar
Standard Widget Toolkit » 4.3 x64
Maven reference: https://mvnrepository.com/artifact/org.eclipse.swt.org.eclipse.swt.win32.win32.x86_64.4.3.swt/org.eclipse.swt.win32.win32.x86_64/4.3
Jar file:
http://central.maven.org/maven2/org/eclipse/swt/org/eclipse/swt/win32/win32/x86_64/4/3/swt/org.eclipse.swt.win32.win32.x86_64/4.3/org.eclipse.swt.win32.win32.x86_64-4.3.jar

Execute Java Class from VB.Net

I have a class in java "Main.class", wrote and stored in %TEMP%. When executing the class through VB.Net Shell, eg:
Shell("cmd.exe /k java %TEMP%\Main.class")
Also when trying to execute manually through CMD: "java %TEMP%\Main.class", I am returned with:
Exception in thread "main" java.lang.NoClassDefFoundError: C:\Users\Ben\AppData\
Local\Temp\Main/class
Caused by: java.lang.ClassNotFoundException: C:\Users\Ben\AppData\Local\Temp\Mai
n.class
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)
Could not find the main class: C:\Users\Ben\AppData\Local\Temp\Main.class. Prog
ram will exit.
However, when I execute Main.class manually through compile.bat - the class runs fine. What is the reasoning for this?
You need to add -classpath to it. Basically the Java interpreter does not know where to find this "Main" class.
CoolBean's solution should work. Something like
Shell("cmd.exe /k java -classpath %TEMP% Main")
Since you can (and are supposed to) omit the .class extension. And like CoolBeans said, you set the directory your class file lives in as the classpath.
While javac takes a file, java takes a Class (in other words, the name of the class after 'public class'), along with what packages it is in (if you don't have "package something;" at the top of your java file, don't worry about this), and it'll look for that class in the classpath you provide, or the current working directory.
If that does end up being the solution, give CoolBeans the accepted answer.
However, an alternative solution is to change the current working directory for Shell to %TEMP%, like:
IO.Directory.SetCurrentDirectory(Environ("TEMP"))
Shell("cmd.exe /k java Main")
Or alternatively look into the Process class, which offers more fine control over launching other programs (and with Process you can also change the directory of the program you're launching without changing the current directory of your own application).
Try this,
Shell("java.exe -cp .;" & Environment.GetEnvironmentVariable("TEMP") & " Main")
OR
Dim args As String = String.Format("-cp .;{0} {1}", Environment.GetEnvironmentVariable("TEMP"), "Main")
Dim procInfo As New ProcessStartInfo
procInfo.FileName = "java.exe"
procInfo.Arguments = args
Dim proc As New Process
proc.StartInfo = procInfo
proc.Start()
proc.WaitForExit()

NoClassDefFoundError on org.jruby.Main

I'm trying to install the hpricot gem on my Windows machine using JRuby 1.4.0RC1. I'm trying to follow the advice to the related question (see -> Installing hpricot for JRuby).
Per the answer's advice I pulled the git head of hpricot and from it's dir ran:
jruby -S rake package_jruby
cd pkg
sudo jgem install ./hpricot-0.8.1-jruby.gem
But when I run this I get the following NoClassDefFoundError:
Exception in thread "main" java.lang.NoClassDefFoundError: org/jruby/Main
Caused by: java.lang.ClassNotFoundException: org.jruby.Main
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.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: org.jruby.Main. Program will exit.
Apparently my JRUBY_HOME\lib\jruby.jar is getting lost.
running jruby -v works fine, so I'm confused where my class path is getting messed up.
It looks like your jruby install isn't complete. Did you grab the bin or src dist? Check if lib/jruby.jar exists, make sure bin/jruby is in the same jruby location as lib/jruby.jar, and test java -jar lib/jruby.jar -e "puts 'hello'" to see if it's functional.
I suspect sudo does not inherit your environment variables. So JRUBY_HOME is gone. Try to add it to jgem profile.
I'm on Windows. I'm not sure if JRuby 1.4 drops the 'j' prefix. jgem isn't recognized, but gem is. Regardless, when I gem environment I get:
C:\tmp\hpricot>gem environment
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.5
- RUBY VERSION: 1.8.7 (2009-09-30 patchlevel 174) [java]
- INSTALLATION DIRECTORY: C:/jruby-1.4.0RC1/lib/ruby/gems/1.8
- RUBY EXECUTABLE: C:/jruby-1.4.0RC1/bin/../bin/jruby.bat
- EXECUTABLE DIRECTORY: C:/jruby-1.4.0RC1/bin/../bin
- RUBYGEMS PLATFORMS:
- ruby
- universal-java-1.6
- GEM PATHS:
- C:/jruby-1.4.0RC1/lib/ruby/gems/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- "install" => "--env-shebang"
- "update" => "--env-shebang"
- REMOTE SOURCES:
- http://gems.rubyforge.org/

Categories

Resources