Application crashes whenever instantiating (empty) constructor - java

I'm creating an Android extension intended to connect to a remote SSH host based on the well known JSch library, so that once the button is pressed, the class is instantiated this way, with no compilation error:
JSch jsch = new JSch();
...but, application crashes!
Looking at the JSch() constructor, there is nothing inside:
public JSch(){
// here there are several commented instructions that need to be
// used just at MAC operational systems (not my OS).
}
If I remove initiation, compiler complains that variable jsch is not initalized.
JSch jsch;
Once I'm compiling with Apache Ant, there is no debug resources that I could use to trace the runtime error.
All tests are being made either within threads or callback methods, giving the same result; I simply cannot initiate the jsch variable, this yields a runtime exception com.jcraft.jsch.JSch.
Does someone has some insights on how to solve that issue ?

I was able to install the Android SDK-tools and after capturing the Log via line command ADB logcat > file.txt, there were the following sentence many times:
java.lang.NoClassDefFoundError: com.jcraft.jsch.JSch
Which means that the extension file (.aix) compiled with apache command ant extensions did not embed the above class within it.
This explains the issue at all (application crashing instantiating above constructor - absent), and the next step is to discover how to encapsulate dependencies - surely in another thread, if I will not be able to do on my own.

Related

ClassNotFoundException while replacing java 6 rmi w/ java 8 [duplicate]

The following method :
private void startServer() { // snippet that starts the server on the local machine
try {
RemoteMethodImpl impl = new RemoteMethodImpl();
Naming.rebind( "Illusive-Server" , impl );
}catch(Exception exc) {
JOptionPane.showMessageDialog(this, "Problem starting the server", "Error", JOptionPane.ERROR_MESSAGE);
System.out.println(exc);
}
}
throws this exception :java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: Interfaces.RemoteMethodIntf
When i start my project, i am greeted with the message in JOptionPane saying problem starting the server and then the above exception. What could be the reason for this ?
I don't understand why does the last statement of exception says class not found exc when i have imported the right packages
There are four cases of this exception.
When exporting: you didn't run 'rmic' and you didn't take the steps described in the preamble to the Javadoc for UnicastRemoteObject to make it unnecessary.
When binding: the Registry doesn't have the stub or the remote interface or something they depend on on its classpath.
when looking up: the client does't have these things on its classpath.
When calling a remote method: you either sent something to the server of a class not present on its CLASSPATH, or received something from the server (including an exception) of a class not on your CLASSPATH: in both cases possibly a derived class or interface implementation of a class or interface mentioned in the remote interface's method signature.
This is case 2. The Registry can't find the named class.
There are several solutions:
Start the Registry with a CLASSPATH that includes the relevant JARs or directories.
Start the Registry in your server JVM, via LocateRegistry.createRegistry().
Use dynamic stubs, as described in the preamble to the Javadoc of UnicastRemoteObject. However you may then still run into the same problem with the remote interface itself or a class that it depends on, in which case 1-3 above still apply to that class/those classes.
Ensure that case (4) above doesn't occur.
Use the codebase feature. This is really a deployment option and IMO something to be avoided at the initial development stage.
Remote Server Error:RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: mathInterface
The error very simple to solve to be perform following steps:
For example your java file consider D drive
Start rmiregistry D drive( example D:\start rmiregistry)then don't start rmiregistry on the other drives, it will yield the above error
(Wherever your file is, start rmiregistry)
I will try to explain it as better as possible what I did:
1st. I declared the classpath variable like follow:
set classpath=%classpath%
set classpath=C:\compiler
set classpath=C:\compiler\libro\cap07\rmi\hello\Hello.java
set classpath=C:\compiler\libro\cap07\rmi\hello\Server.java
set classpath=C:\compiler\libro\cap07\rmi\hello\Client.java
(All in one lineset:
set classpath=%classpath%;C:\compiler;C:\compiler\libro\cap07\rmi\hello\Hello.java;C:\compiler\libro\cap07\rmi\hello\Server.java;C:\compiler\libro\cap07\rmi\hello\Client.java)
(I'm not sure if the .java files were nesesary, but I also wrote them for doubts).
2nd. I compilered with the line javac -d C:\compiler Hello.java Server.java Client.java. Where C:\compiler is the root directory like src on Eclipse IDE.
3rd. I ran the start rmiregistry line. (and don´t matter where you run it, it's the same).
4th. I ran:
start java -classpath C:\compiler -Djava.rmi.server.codebase=file:C:\compiler/ libro.cap07.rmi.hello.Server
You already know C:\compiler, but you need define packages address on the last to that the command can find the .class files. Open any .java file and copy the package address without packages sentense. You will see when you open the src directory (in my case C:\compiler), you find all directory sequence created. When this command line is created correctly, no matter where you will run it, C:, D:, src, anywhere it wil run.
5th. And finally, I ran the Client class with:
java -classpath C:\compiler libro.cap07.rmi.hello.Client
In conclusion, if the classpath variable won't created or it's to created wrong or the sentence of 4th point is not addressed well the JVM throws the same or similar error. Search there!
(Sorry my english).
You can launch rmiregistry from anywhere but you have to make sure that the compiled classes are already in your classpath. For example:-
E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes>set classpath=%classpath%;E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes <ENTER>
E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes>c: <ENTER>
C:\>rmiregistry
And the above should work fine.
In general, if you launch rmiregistry from the root location of the compiled classes (above example it is E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes), that will work because . (dot - current directory) is already set in your classpath.
But as soon as you remove . (dot - current directory) from your classpath, the above working condition will also fail.
Hope I have explained in details.
I got this same issue, and a different solution worked for me. I was running two different IntelliJ projects, with a copy of the interface in each project. One of them was in a package, and the other one wasn't, and that was what was causing this error.
Solutions:
Make sure the interface copies aren't in a package.
Make sure the interface copies have the exact same package name.

play application startup isses with VM variable -Dprecopiled=true?

I'm using play1-1.3.0. In production mode, I'm starting up my application, by using this command play start MyApp -Dprecompiled=true i got this error message in logs.
play:424 - Precompiled classes are missing!!
I exactly don't know why I'm getting this error message.
You need to of ran play precompile first this will compile classes ready to use

Java RMI Remote Interface Tutorial - error: unmarshalling arguments [duplicate]

The following method :
private void startServer() { // snippet that starts the server on the local machine
try {
RemoteMethodImpl impl = new RemoteMethodImpl();
Naming.rebind( "Illusive-Server" , impl );
}catch(Exception exc) {
JOptionPane.showMessageDialog(this, "Problem starting the server", "Error", JOptionPane.ERROR_MESSAGE);
System.out.println(exc);
}
}
throws this exception :java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: Interfaces.RemoteMethodIntf
When i start my project, i am greeted with the message in JOptionPane saying problem starting the server and then the above exception. What could be the reason for this ?
I don't understand why does the last statement of exception says class not found exc when i have imported the right packages
There are four cases of this exception.
When exporting: you didn't run 'rmic' and you didn't take the steps described in the preamble to the Javadoc for UnicastRemoteObject to make it unnecessary.
When binding: the Registry doesn't have the stub or the remote interface or something they depend on on its classpath.
when looking up: the client does't have these things on its classpath.
When calling a remote method: you either sent something to the server of a class not present on its CLASSPATH, or received something from the server (including an exception) of a class not on your CLASSPATH: in both cases possibly a derived class or interface implementation of a class or interface mentioned in the remote interface's method signature.
This is case 2. The Registry can't find the named class.
There are several solutions:
Start the Registry with a CLASSPATH that includes the relevant JARs or directories.
Start the Registry in your server JVM, via LocateRegistry.createRegistry().
Use dynamic stubs, as described in the preamble to the Javadoc of UnicastRemoteObject. However you may then still run into the same problem with the remote interface itself or a class that it depends on, in which case 1-3 above still apply to that class/those classes.
Ensure that case (4) above doesn't occur.
Use the codebase feature. This is really a deployment option and IMO something to be avoided at the initial development stage.
Remote Server Error:RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: mathInterface
The error very simple to solve to be perform following steps:
For example your java file consider D drive
Start rmiregistry D drive( example D:\start rmiregistry)then don't start rmiregistry on the other drives, it will yield the above error
(Wherever your file is, start rmiregistry)
I will try to explain it as better as possible what I did:
1st. I declared the classpath variable like follow:
set classpath=%classpath%
set classpath=C:\compiler
set classpath=C:\compiler\libro\cap07\rmi\hello\Hello.java
set classpath=C:\compiler\libro\cap07\rmi\hello\Server.java
set classpath=C:\compiler\libro\cap07\rmi\hello\Client.java
(All in one lineset:
set classpath=%classpath%;C:\compiler;C:\compiler\libro\cap07\rmi\hello\Hello.java;C:\compiler\libro\cap07\rmi\hello\Server.java;C:\compiler\libro\cap07\rmi\hello\Client.java)
(I'm not sure if the .java files were nesesary, but I also wrote them for doubts).
2nd. I compilered with the line javac -d C:\compiler Hello.java Server.java Client.java. Where C:\compiler is the root directory like src on Eclipse IDE.
3rd. I ran the start rmiregistry line. (and don´t matter where you run it, it's the same).
4th. I ran:
start java -classpath C:\compiler -Djava.rmi.server.codebase=file:C:\compiler/ libro.cap07.rmi.hello.Server
You already know C:\compiler, but you need define packages address on the last to that the command can find the .class files. Open any .java file and copy the package address without packages sentense. You will see when you open the src directory (in my case C:\compiler), you find all directory sequence created. When this command line is created correctly, no matter where you will run it, C:, D:, src, anywhere it wil run.
5th. And finally, I ran the Client class with:
java -classpath C:\compiler libro.cap07.rmi.hello.Client
In conclusion, if the classpath variable won't created or it's to created wrong or the sentence of 4th point is not addressed well the JVM throws the same or similar error. Search there!
(Sorry my english).
You can launch rmiregistry from anywhere but you have to make sure that the compiled classes are already in your classpath. For example:-
E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes>set classpath=%classpath%;E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes <ENTER>
E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes>c: <ENTER>
C:\>rmiregistry
And the above should work fine.
In general, if you launch rmiregistry from the root location of the compiled classes (above example it is E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes), that will work because . (dot - current directory) is already set in your classpath.
But as soon as you remove . (dot - current directory) from your classpath, the above working condition will also fail.
Hope I have explained in details.
I got this same issue, and a different solution worked for me. I was running two different IntelliJ projects, with a copy of the interface in each project. One of them was in a package, and the other one wasn't, and that was what was causing this error.
Solutions:
Make sure the interface copies aren't in a package.
Make sure the interface copies have the exact same package name.

Debugging JNLP started application

I created a Java desktop-application (using Swing) and am now trying to make it work by starting it from the net using JNLP. The application works fine when I start it from the terminal, but as soon as I launch it from JNLP, it does not close. I have to manually kill the process every time.
I read that there might be a problem if my JFrame uses DISPOSE_ON_CLOSE as the default close-operation, but it doesn't. It uses DO_NOTHING_ON_CLOSE (implicitly). Also, I'm explicitly calling System.exit(0) after releasing all my objects:
f = new JFrame("Pacman");
f.addWindowListener(new WindowAdapter() {
#Override
public void windowClosing(WindowEvent e) {
// Terminate the Game-loop:
GameLoop.INSTANCE.stopLoop();
// Close the application:
System.exit(0);
}
});
I guess that there might be an exception thrown when I close the application, but I can't find a way to get the console-output (e.g. the Stack-Trace) of a running application started with JNLP. Here's what I tried:
Start javaws with the debugging parameters and connect with jconsole (works but I can't find any exception- or console-ouput).
Start javaws with the debugging parameters and attach IntelliJ debugger to it (also works but does not give me any output)
So, how can I start the application with JNLP and get the output (written to the default out- and error-streams), as if I would do with a normal desktop application?
Solution #1 - Enable Java Console, and look for exceptions.
You can do it via Java Control Panel. Switch to Advanced tab, and in the Java Console make sure Show console is selected.
Then, run your application and monitor the console for exceptions. Fix the exception.
Solution #2 - Debug your running application (properly).
Start the Web Start app like this (for Java 1.6 and newer):
javaws -verbose -J-Xdebug -J-Xnoagent -J-Xrunjdwp:transport=dt_socket,server=n,suspend=y,address=8123 http://myserver.com/path/to/myapp.jnlp
If using earlier java versions (1.4.2, 1.5) set the environment variable, like this:
set JAVAWS_VM_ARGS="-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=n,suspend=y,address=8123"
and run the app via:
javaws http://myserver.com/path/to/myapp.jnlp
When the app runs:
Attach a debugger (Eclipse will do - use Run => Debug Configurations => Remote Java Application, and in Connection Properties panel enter the port passed in the parameters to javaws (in this case: 8123).
Set a breakpoint inside your windowClosing method.
Try to close your application - Eclipse should break the execution on your breakpoint
Step into the GameLoop.INSTANCE.stopLoop() method to see where/when it hangs.
Don't expect to see a solutions in the console, just step through the code with a debugger - if the application hangs, it will show you where.
There are times when even the console doesn't show anything, for example when there is a problem with the TLS/SSL handshake (i.e. a close_notify or handshake_failure). In these cases you need to do the following:
Enable the Java logs and tracing in the Java Control Panel > Advanced.
Enable parameters for debugging Java & launching the JNLP, there are two ways you can do it:
2.a. Download the JNLP file and execute it from command line (the SET command is not required in this particular case).
set JAVA_TOOL_OPTIONS=-Djavax.net.debug=all
javaws -wait jnlp.jnlp
2.b. Add arguments (i.e. -Djavax.net.debug=all) for the JVM in the Java Control Panel > Java > View (this is not required in this particular), and launch the JNLP file from browser:
The logs and traces are located in the log directory from the Java Deployment Home from where I paste these locations:
a. Windows XP: %HOME%\Application Data\Sun\Java\Deployment
b. Windows 7/Vista: %APPDATA%\..\LocalLow\Sun\Java\Deployment
c. Linux/Solaris: %HOME%/.java/deployment
This answer is an alternative to npe answer to enable the remote debug (Windows).
Go to Control Panel;
Click on Java, to open Java Control Panel;
Inside of Java Control Panel, go to Java tab, and click "View";
This will open a window with installed java versions. On runtime parameters put "-Xdebug -Xrunjdwp:transport=dt_socket,address=8123,server=y,suspend=n" (if you want to debug when application is starting, change to "suspend" to "y", that will make the application stop until an editor connect remotely);
Afer that, configure you editor to debug remotely to the configured port (localhost:8123 in this case).

Doubt in Java Service wrapper while running jar application fom window service

I have a jar application which process and converts file into csv file. I have made it to run in windows service using Java Service Wrapper. It got installed my jar application successfully when I run "InstallApp-NT. Bat" file and starts running my application when I run "app" command.
But when I try to start the service in services, its not starting and showing following message in dialog box<
Windows could not start the generic Preprocessor application on Local Computer. For more information, review the System Event Log. If this is a non-microsoft service, contact the service vendor, and refer to service-specific error code1
I have the system log file and it showing the below error message
System Event log:
--> Wrapper Started as Service
Java Service Wrapper Community Edition 3.3.2
Copyright (C) 1999-2009 Tanuki Software, Ltd. All Rights Reserved.
http://wrapper.tanukisoftware.org
Launching a JVM...
WrapperManager: Initializing...
WrapperSimpleApp:
WrapperSimpleApp: Encountered an error running main:
WrapperSimpleApp: java. Lang. NullPointerException
WrapperSimpleApp: at java. Util. Hashtable. Put(Hashtable. Java: 396)
WrapperSimpleApp: at java. Util. Properties. SetProperty(Properties. Java: 128)
WrapperSimpleApp: at java. Lang. System. SetProperty(System. Java: 701)
WrapperSimpleApp: at com. Dnb. Genericpreprocessor. Process. ProcessRunner. Main(Unknown Source)
WrapperSimpleApp: at sun. Reflect. NativeMethodAccessorImpl. Invoke0(Native Method)
WrapperSimpleApp: at sun. Reflect. NativeMethodAccessorImpl. Invoke(NativeMethodAccessorImpl. Java: 39)
WrapperSimpleApp: at sun. Reflect. DelegatingMethodAccessorImpl. Invoke(DelegatingMethodAccessorImpl. Java: 25)
WrapperSimpleApp: at java. Lang. Reflect. Method. Invoke(Method. Java: 585)
WrapperSimpleApp: at org. Tanukisoftware. Wrapper. WrapperSimpleApp. Run(WrapperSimpleApp. Java: 238)
WrapperSimpleApp: at java. Lang. Thread. Run(Thread. Java: 595)
<-- Wrapper Stopped
I don't think any error in application code because it running fine when run "app" command. Please help what I should now. Thanks in advance.
I am using the following code in com.dnb.genericpreprocessor.process.ProcessRunner class.
String projectHome = "D:\BL";
System.setProperty("project.home", projectHome);
System.setProperty("log.home",System.getenv("DBE")); ---> DBE is the envirinment variable I created in user variables.
When I run the application by giving app command... Its running the application by printing the environment value but showing the same error when I start it in service.
Answering your question update that you phrased as an answer, you need to ensure that the variable is in fact set in the specific environment where you are running the application. It appears that it is not. In fact, to avoid the NullPointerException, I would modify your code to something like:
String loghome = System.getenv("DBE");
if (loghome == null) {
// LOG A COMPLAINT that the environment variable is not set
loghome = "some reasonable default value";
}
System.setProperty("log.home", loghome);
so at least your application won't fail with an obtuse NPE if it is executed in the wrong environment.
Check com.dnb.genericpreprocessor.process.ProcessRunner if that is your code and see what data you are setting in System property. NullPointer is telling that the key or the value you passed is Null.
Check your wrapper.config; you need to have all the necessary jars in order, and each with their own index number (for some reason):
wrapper.java.classpath.1=../lib/wrapper.jar
wrapper.java.classpath.2=%JAVA_HOME%/lib/tools.jar
...
Just a first thought.
I am not familiar with the proprietary solution you are using, but it seems you somehow configured it wrong.
Looks like some parameter the wrapper should have is null and is propagating all the way up until the system is trying to set it as property.
Maybe you should put your 'DBE' enviroment in the system variables not user variables.
Windows service starts at system account.

Categories