Running a jar vs running classes under Linux
I still can't figure this out.
I have a jar file that I am trying to run on my Linux server.
The jar file runs on my local machine.
If I try to run the jar file on the linux box I get -
Exception in thread "main" java.lang.NoClassDefFoundError:
javax/sql/ConnectionPoolDataSource
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:120)
If I un jar the file, all classes run correctly.
I have explicitly set the classpath from the command line on each try. Can anyone explain why it works one way and not the other?
Thank you for your help. HOW DO I DO THAT?
And, If I don't already have that information in the jar manifest, why does the jar work on my other machines?
And, I thought the reason you would jar the files up is to make it easy to port to other systems. If I have to change the manifest for each machine that doesn't make it very portable.
I am really frustrated with it and can't seem to find the solution.
Similar Messages
-
Can't run eclipse under Linux OS
When I run eclipse_linux_gtk 3.1 under Linux ( kernel 2.6.7, gnome 2.8, sun jdk 1.5.0), I got the following error message.
What is wrong with it?How should I do to make it work?
!SESSION Oct 11, 2004 00:36:59.306 ---------------------------------------------
eclipse.buildId=M200409161125
java.version=1.5.0
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=linux, ARCH=x86, WS=gtk, NL=en_US
!ENTRY org.eclipse.osgi Oct 11, 2004 00:36:59.334
!MESSAGE Startup error
!STACK 1
java.lang.RuntimeException: Exception while creating System Bundle: Unable to find system bundle manifest file.
at org.eclipse.osgi.framework.internal.core.Framework.createSystemBundle(Framework.java:253)
at org.eclipse.osgi.framework.internal.core.Framework.initialize(Framework.java:152)
at org.eclipse.osgi.framework.internal.core.Framework.(Framework.java:95)
at org.eclipse.osgi.framework.internal.core.OSGi.createFramework(OSGi.java:90)
at org.eclipse.osgi.framework.internal.core.OSGi.(OSGi.java:31)
at org.eclipse.core.runtime.adaptor.EclipseStarter.startup(EclipseStarter.java:215)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:127)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.eclipse.core.launcher.Main.basicRun(Main.java:185)
at org.eclipse.core.launcher.Main.run(Main.java:704)
at org.eclipse.core.launcher.Main.main(Main.java:688)
!SESSION Mon Oct 11 00:36:59 GMT 2004 ------------------------------------------
!ENTRY org.eclipse.core.launcher 4 0 Oct 11, 2004 24:36:59.376
!MESSAGE Exception launching the Eclipse Platform:
!STACK
java.lang.NullPointerException
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:138)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.eclipse.core.launcher.Main.basicRun(Main.java:185)
at org.eclipse.core.launcher.Main.run(Main.java:704)
at org.eclipse.core.launcher.Main.main(Main.java:688)I love eclipse and run it under windows very well.
Now,I install a Linux OS in my computer,and want to work under it, but I get the same error log everytime.
What others do who use eclipse under Linux?Is it work well? -
Reduce number of running thread under Linux
Hello,
How can reduce the number of running thread for coldfusion MX
7.0.2 server under Linux (they are almost 30; )If you create a pool of any sort you will need a point where all requests for a resource from the pool must go via, and that piece of code could potentially become a bottle neck. But if you develop it well there will be a very small piece of code that is sychrnonized that will either put a request in a queue as there are no resources available, or it will provide the requested resource. As far as i am aware there is no safe way around this as you will have multiple threads requesting the resource.
-
Hi
I am a newbie on Linux environment, now I am using Redhat AS 2.1. I've just finished installed oracle 9i on my Linux and it went successfully.
The problem is, I can't find the Oracle menu on my Redhat GUI (as in Windows), so I need a guidance of how to access & run my oracle on my Linux.
any helps / clues will be appreciated
thxHi,
The installation on Linux doesn't create icons on the GUI as in Windows environment.
You can run the tools and the sqlplus from a terminal.
The tools should be find in: /your oraclehome/bin
Use oemapp to load Enterprise Manager and other tools to create, modify users, instances, etc.
Good Luck!!
Eduardo -
Suppose to package all necessary *.class in example.jar in following way,
bin.start.class
business.bus.class
and the class file that contain main is bin.start.class.
There is no problem to run following under linux shell prompt. java VM is under PATH searching path. i.e.
$java -classpath example.jar bin.start
However, there is some problem to run a script which contains 'java -classpath example.jar bin.start' under linux shell prompt.
May I have any clue to identify this problem?
Thanks in advance.For case 1: Does any case work? When I see "[un]able to locate the main method" then I think that that the class was found but that the main method is not declared properly.
Of course, main must be declared with exactly these keywords:
static public void main( String arg[]) {
...For case 2: you still have some kind of classpath problem.
If your script really has the line
java -classpath example.jar bin.start
then I still think your current working directory at the time that this line is run not that same directory as where the jar file is.
If you have JAVA_HOME defined, you might want to try:
pwd
$JAVA_HOME/bin/java -classpath example.jar bin.start
Another suggestion: If your $PATH variable is long, try to shorten it to a short list of directories. You can test with just /bin:/usr/bin .
Also, is your shell Bash or C-shell? Is your script Bourne shell (/bin/sh) or Bourne? -
Running JVM in Linux with execl
Why if I run JVM under Linux and with execl the first argument is lost?
For example if I want to run java -version I have to do:
execl("/usr/lib/java5/bin/java","nothing","-version");
If I do execl("/usr/lib/java5/bin/java","-version"); it doesn't works and appears the help message that appears when you are wrong with the parameters.
This is an innocent thing when you know it, but that has caused me a lot of headaches and debug time and now I'm curios about it ;)
PD: I use jdk-1_5_0_01 and Suse 9.1
A lot of thanks in advance,/* a.c */
#include <stdio.h>
#include <stdlib.h>
int main() {
int r=execl("./b","nothing","-version",NULL);
printf("%d\n",r);
/* b.c */
#include <stdio.h>
int main(int argc,char *argv[]) {
int i;
for(i=0;i<argc;i++) printf("%d %s\n",i,argv);
$ gcc a.c -o a
$ gcc b.c- o b
$ ./a
0 nothing
1 -version -
SubNotFoundException under Linux not under Windows
Hi,
I got a RMI client server application. The server runs normal on my windows machine with JRE 1.5. But when I want to run it on my linux server with JRE 1.4, I get the following error:
java.rmi.StubNotFoundException: Stub class not found: .....
I used an Ant Build.xml file to create jar (2 --> 1 remote.jar and 1 server.jar) files. In the javac I set the target to 1.1. In rmic I used stubversion and set to 1.1. All my remote objects are in a seperate jar file that is included in my path when I start my server. I start my server with a bat and a sh file.
run.bat (under Windows)
set CPBEFORE=%CLASSPATH%
set CLASSPATH=%CLASSPATH%;PpdaRemote.jar
start rmiregistry 10001 -J- Djava.rmi.server.hostname=willemc
set CLASSPATH=%CPBEFORE%;
java -jar PpdaServer.jar
run.sh (under Linux)
CPBEFORE=$CLASSPATH
export CLASSPATH="$CLASSPATH:PpdaRemote.jar"
rmiregistry 10001 -J- Djava.rmi.server.hostname=willemc &
export CLASSPATH=$CPBEFORE
java -jar PpdaServer.jar
Can anybody think of a solution for this. I have been working on it for a couple of hours. Upgrading my server to 1.5 is not possible (it's a sgi server).
Thanks,
WillemNevermind. Fixed my own problem.
-
Exception in html parser under Linux
Hi all,
Following code is copied from Tech Tip 23Sep1999. I have compiled it and run it under Win98. It works fine for any uri. However, when I try to run it under Linux, it throws exceptions. I noticed that some web site can be parsered with the program in Linux but some can't. I wonder the different between those platforms. Anyone can tell me how to make the program works under Linux.
Rgds,
unplug
configuration
RedHat 7.1
JDK1.3.1
Failed: java GetLinks http://java.sun.com
Worked: java GetLinks http://www.apache.org
--begining of code
import java.io.*;
import java.net.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
class GetLinks {
public static void main(String[] args) {
EditorKit kit = new HTMLEditorKit();
Document doc = kit.createDefaultDocument();
// The Document class does not yet
// handle charset's properly.
doc.putProperty("IgnoreCharsetDirective",
Boolean.TRUE);
try {
// Create a reader on the HTML content.
Reader rd = getReader(args[0]);
// Parse the HTML.
kit.read(rd, doc, 0);
// Iterate through the elements
// of the HTML document.
ElementIterator it = new ElementIterator(doc);
javax.swing.text.Element elem;
while ((elem = it.next()) != null) {
SimpleAttributeSet s = (SimpleAttributeSet)
elem.getAttributes().getAttribute(HTML.Tag.A);
if (s != null) {
System.out.println(
s.getAttribute(HTML.Attribute.HREF));
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
// Returns a reader on the HTML data. If 'uri' begins
// with "http:", it's treated as a URL; otherwise,
// it's assumed to be a local filename.
static Reader getReader(String uri)
throws IOException {
if (uri.startsWith("http:")) {
// Retrieve from Internet.
URLConnection conn=
new URL(uri).openConnection();
return new
InputStreamReader(conn.getInputStream());
} else {
// Retrieve from file.
return new FileReader(uri);
--End of code
--Exception in Linux
Exception in thread "main" java.lang.NoClassDefFoundError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:120)
at java.awt.Toolkit$2.run(Toolkit.java:512)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:503)
at javax.swing.text.html.CSS.getValidFontNameMapping(CSS.java:932)
at javax.swing.text.html.CSS$FontFamily.parseCssValue(CSS.java:1789)
at javax.swing.text.html.CSS.getInternalCSSValue(CSS.java:531)
at javax.swing.text.html.CSS.addInternalCSSValue(CSS.java:516)
at javax.swing.text.html.StyleSheet.addCSSAttribute(StyleSheet.java:436)
at javax.swing.text.html.HTMLDocument$HTMLReader$ConvertAction.start(HTM
LDocument.java:2536)
at javax.swing.text.html.HTMLDocument$HTMLReader.handleStartTag(HTMLDocu
ment.java:1992)
at javax.swing.text.html.parser.DocumentParser.handleStartTag(DocumentPa
rser.java:145)
at javax.swing.text.html.parser.Parser.startTag(Parser.java:333)
at javax.swing.text.html.parser.Parser.parseTag(Parser.java:1786)
at javax.swing.text.html.parser.Parser.parseContent(Parser.java:1821)
at javax.swing.text.html.parser.Parser.parse(Parser.java:1980)
at javax.swing.text.html.parser.DocumentParser.parse(DocumentParser.java
:109)
at javax.swing.text.html.parser.ParserDelegator.parse(ParserDelegator.ja
va:74)
at javax.swing.text.html.HTMLEditorKit.read(HTMLEditorKit.java:239)
at GetLinks.main(GetLinks.java:23)Support for CSS and clearly defined.Also Dictionary getDocumentProperties() is not properly exaplained meaning it doesnt give methods to get all the properties a HTML document can have.
-
Portege Z930 - slow Wi-Fi on battery under Linux
Hi,
I've just bought a Z930 and I run it under Linux Mint and Windows 7.
I've a problem under Linux that I don't have on Windows.
When I put my computer on battery, there is a significative signal lowering.
Do somebody why there is such a problem ? Can we fix it by configuring my network device ?
Thanks for your help !
BadmaulSounds like the Wifi driver needs updating, perhaps try an Ubuntu Live CD v12 and see how that goes. Ubuntu is very Toshiba friendly now.
-
Java running under linux with crontab
I'm having a problem:
i want to run a java program under linux with crontab.
my classes are in a directory and aren't in a package. i run em by invoking ./start which is a small script that i wrote. The script is in the same dir as the classes and invokes java by "java Main >>logjava.txt " but this doesn't seem to work all i get is an empty logfile
i need to run the program every day at 0800 so i inserted the following in crontab:
0 8 * 1-5 /var/"path"/start > logjava (where path is the path to the classes dir)
if i run the cmdline from anywhere on the prompt i get the result i want. I think it's because the cron runs it from the root dir thus making java unable to find the classes
Any suggestions would be welcome. or can some1 tell me how to make linux executables from the java (i usually use jsmooth for the windows exe)You can execute several commands in the process started by cron. You separate them using semicolons.
Have you tried a cron entry like this:
0 8 * 1-5 cd /var/"path";pwd;echo $PATH; ./start > logjavaOr, you may need to make sure the process started by cron gets the same environment as your interactive shells do, by explicitly loading your setup or .login scripts:
0 8 * 1-5 . $HOME/.setup;cd /var/"path";pwd;echo $PATH; ./start > logjava -
Loss of keyboard focus in Java appl running under linux
I have a small sample program that replicates my problem. When this program is run a window is created. If you select File->New another instance of the program window is created. Now if you try to go back and bring to front the first window, keyboard focus is not
transferred when run under linux. You can only type in the second window. The expected behavior does happen in Windows.
> uname -a
Linux watson 2.6.20-1.2933.fc6 #1 SMP Mon Mar 19 11:38:26 EDT 2007 i686 i686 i386 GNU/Linux
java -versionjava version "1.5.0_11"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03)
Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode, sharing)
javac -versionjavac 1.5.0_11
import java.awt.event.*;
import javax.swing.*;
class SwingWindow extends JFrame {
SwingWindow() {
super("SwingWindow");
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu("File");
JMenuItem newItem = new JMenuItem("New");
newItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
SwingWindow.createAndShowGUI();
fileMenu.add(newItem);
menuBar.add(fileMenu);
setJMenuBar(menuBar);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JTextField text = new JTextField(200);
getContentPane().add(text);
pack();
setSize(700, 275);
public static void createAndShowGUI() {
JFrame frame = new SwingWindow();
frame.setVisible(true);
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}You can implement the FocusListener interface. When
the first JFrame gains focus, call
text.requestFocusInWindow(). I hope this helps.The call requestFocusInWindow is not helping, perhaps even making it worse.
The problem seems to be that I am in the situation where the call
KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner()
is returning the expected Component. The problem is that the KeyListener class that is registered with the Component is not being called when a key is being pressed.
The issue is that I have a component that has the keyboard focus, but the KeyListener class
is not responding.
This seems to be a linux only problem which makes it only mysterious. -
I keep trying to download the windows version of firefox so I can run it under wine on linux but all I can find is the linux version because the web site automatically detects the os. Any ideas on how I could do this?
Download from here: <br />
http://www.mozilla.com/en-US/firefox/all.html -
Opening a Powerpoint in JSP and run under Linux
Hi,
I need to have a JSP page that provides a link to open a powerpoint file and this JSP is to be run under Linux. When I try to click on the link in Linux to open the powerpoint, it gives me a lot of junk characters. Can somebody please help mi, thanks a million!You have the mimetype for the HTTP response set to something other than what will make the browser start a powerpoint viewer and direct the content of the HTTP response to it.
In your jsp use the setHeader(String key,String key) method to set the value of "Content-Type" to the mimetype for powerpoint.
Of course the users must have browsers that are configured to launch a powerpoint viewer or plug-in. If you provide the correct mimetype and peoples browsers desn't have this, then they will get the "save to file" dialog box. -
Font problems running a swing app under Linux
I have an application running well under the Win family (NT, 2000, etc.)... and it also runs well under a Linux Red Hat os... but in the linux environment I've observed the folloowing font errors displayed in the screen:
Font specified in font.properties not found [--symbol-medium-r-normal--*-%d-*-*-p-*-adobe-fontspecific]
this is a unexpected issue because I'm not setting any font in my code... How can I solve it ?
It's a Java or OS configuration problem ??Here is a solution:-
Copy SYMBOL.TTF to /usr/java/jdk1.3.1_01/jre/lib/fonts or wherever.
Note the copy should have lower case name!
Do a chmod 444 symbol.ttf
I don't say where to get a copy from but you can imagine!!
Modify the file fonts.dir in the same directory as follows:
Change the first line by 1 ie if its 72 change to 73.
Insert the following line:
symbol.ttf -monotype-symbol-medium-r-normal--0-0-0-0-p-0-abode-fontspecific
You have to do the above as root of course. -
This is probably a fairly stupid question, but I wasn't able to find any documentation for this particular problem.
I created your basic HelloWorld project with the following directory structure:
HelloWorld
|- classes/hello/world/HelloWorld.class
|- src/java/hello/world/HelloWorld.java
|- Manifest.txt
Manifest.txt only has the following line:
Main-Class: hello.world.HelloWorld
Now, I try to jar this up and run it as a jar by performing the following in the HelloWorld directory:
jar cfm hello.jar Manifest.txt classes/wgen/world/HelloWorld.class
java -jar hello.jar
And I get a NoClassDefFoundError: hello/world/HelloWorld exception. What do I have to do so I can run HelloWorld from the jar?
Thanks in advance!Did you mean classes/wgen/world/HelloWorld.class or classes/hello/world/HelloWorld.class? You used both in your post.
What is the package statement, if any, in the HelloWorld.java source code? How did you test the HelloWorld app before you jar'ed it? What is the output of "jar tf hello.jar"
Assuming the directory path is classes/hello/world/HelloWorld.class, the source code starts with "package hello.world;" and your existing manifest then something like this cd classes
jar cfm hello.jar Manifest.txt hello/world/HelloWorld.class
java -cp hello.jar hello.world.HelloWorld
java -jar hello.jarI always test a jar using the -cp option first to make sure I jar'ed the classes correctly, then test it with the -jar option. If it does not work with -cp then the classes are not jar'ed correctly. If it works with -cp but does not work with -jar, then the manifest is incorrect.
Maybe you are looking for
-
How to search for upper/lower case using string using JAVA!!!?
-I am trying to write a program that will examine each letter in the string and count how many time the upper-case letter 'E' appears, and how many times the lower-case letter 'e' appears. -I also have to use a JOptionPane.showMessageDialog() to tell
-
BPEL fault policy takes more time, when rethrowing
Hi All, I have a scenario where BPEL fault policy is taking more time to re-throw the fault back to BPEL Scenario: 1) Partner link service throws as business exception 2) This exception is first caught by BPEL fault policy, this in-turn will invoke "
-
Find my phone no longer allows us to send a message??
Did they remove this option?
-
Using the following erp system with oracle
Dear all, Does anyone have experience in using the Infor ERP LN with oracle. Are they fully compatible...the reason why I am asking is to make a good arguement why our company needs to oracle when we migrate over to our new ERP system which is infor
-
Changes in line definition when converting from Freehand to jpeg format
When I change my maps into jpeg formats, the lines change. e.g. a dahed line may become dashes and dots, not as they were drawn. This has happened since I had a new hard disk in my iMac. Can anyone help? Blodwin