connect to server socket running in eclipse - java

I want to connect a Client written in Perl and running via command line to a server written in java and running in Eclipse. It don't work, it's because the server is running in Eclipse ? when I try to run the server via command line I got an error, but in eclipse it work fine
java MultiThreadServer
Exception in thread "main" java.lang.NoClassDefFoundError: MultiThreadServer (wrong name: inet/MultiThreadServer)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

I think that is a classpath issue.
The NoClassDefFoundError indicates that the classloader can't find the .class file that you're trying to use. You should set the classpath when executing your code.
See
Classpath in Java

Related

Force IntelliJ project to use Scala compatible with Java 6

I have this project in IntelliJ IDEA which uses Scala. I need it to be compatible to run on Java v1.6. I configured the project as such, and I even only have Java 6 in my development environment. However, when I build the project and run it I get the following:
Exception in thread "main" java.lang.UnsupportedClassVersionError: scala/Function1 : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at myproject.Main.main(Main.scala)
It appears as so there's still some class in my project compiled for Java 8. Could it be that the Scala libraries I have are compiled for Java 8? These are the libraries downloaded by IntelliJ IDEA. How can I solve this?

exceptions on executing hdfs namenode -format

I get following exception, when I execute hdfs namenode -format command:
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/hadoop/util/PlatformName : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: org.apache.hadoop.util.PlatformName. Program will exit.
This issue is related to java version mismatch i.e the version with which hadoop is compiled is higher than the jdk version installed on your machine.Install proper jdk version and set JAVA_HOME properly

java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing in Intellij

I used Intellij Idea 12 Community edition. I am trying to create test case for my class by creating test case. When i run my test case it says
java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:10)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:44)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.ClassNotFoundException: org.hamcrest.SelfDescribing
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:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 25 more
How would i run test case in Intellij. I included the junit4.11 jar file to my module
Did you include the hamcrest-core-1.3.jar file in your classpath? If not included means include that jar and try once again.
add junit.jar to your project dependence.
you may also need to add hamcrest.jar in addition.
Open File->Project Structure,Click Modules->Dependences,add junit.jar.
Latest version of hamcrest-all is available at:
https://search.maven.org/search?q=a:hamcrest-all
Download this version (as opposed to the hamcrest-core) and that should do it.
If you come across this (and a few other threads) on this error and adding the jar to dependencies doesn't work, you will need to add to the general java classpath.
I encountered this error in OSX where maven would download the dependency, but not find it when in fork mode.
Adding all the hamcrest jars to Library/Java/Extensions finally fixed the problem when nothing else would.

Having issues trying to run a standalone Java 6 program which is packaged in a war file and deployed under tomcat 7

The issue is that when I run it via Eclipse Juno by clicking on it and "Run as Java Application" it works,
but it needs to be to run in a Linux shell script or at least from the Linux shell.
I need it to append all the jar files from $CATALINA_HOME/webapps/myapp/WEB-INF/lib to my classpath.
Here's my code:
package com.myapp.client;
public class ClientApp {
public static void main(String args[]) {
System.out.println("Hi Client");
}
}
When I cd into $CATALINA_HOME/webapps/myapp/WEB-INF/classes/com/myapp/client issue the following command:
java -classpath "/home/devuser/DevTools/apache-tomcat-7.0.32/webapps/myapp/WEB-INF/lib/*:." ClientApp
I receive this exception:
Exception in thread "main" java.lang.NoClassDefFoundError: ClientApp (wrong name: com/myapp/client/ClientApp)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: ClientApp. Program will exit
When I go to my home dir (/home/devuser) and type this in, it still doesn't work:
java -classpath "/home/devuser/DevTools/apache-tomcat-7.0.32/webapps/myapp/WEB-INF/lib/*:." $CATALINA_HOME/webapps/myapp/WEB-INF/classes/com.myapp.ClientApp
Exception in thread "main" java.lang.NoClassDefFoundError: /home/devuser/DevTools/apache-tomcat-7/0/32/webapps/myapp/WEB-INF/classes/com/myapp/ClientApp
Caused by: java.lang.ClassNotFoundException: .home.devuser.DevTools.apache-tomcat-7.0.32.webapps.myapp.WEB-INF.classes.com.myapp.ClientApp
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:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: /home/devuser/DevTools/apache-tomcat-7.0.32/webapps/myapp/WEB-INF/classes/com.myapp.ClientApp. Program will exit.
Thank you for taking the time to read this... Would appreciate it if someone could assist me.
All of your libraries and classes need to be in your classpath, then the next argument is the path to your class.
java -cp '.:/path/to/libdir/*:/path/to/myapp.war' com.myapp.client.ClientApp

How to run a project that written in NetBeans on another computer?

I wrote a project in NetBeans IDE in my computer, and I ran it. That was OK. I transferred it into my Friend's computer. I ran it with NetBeans, but I got these errors:
java.lang.UnsupportedClassVersionError: friendspro/Server/RunServer : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: friendspro.Server.RunServer. Program will exit.
Exception in thread "main" Java Result: 1
///
When I ran my project in my computer in CMD, I got the same error:
C:\Users\Blue\Desktop\FriendsPro\src\friendspro\Server>java RunServer -ORBIniti
alRef NamingServic=corbaloc::localhost:1049/NameService
Exception in thread "main" java.lang.NoClassDefFoundError: RunServer (wrong name
: friendspro/Server/RunServer)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:14
2)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:476)
It's not the same error. Your friend has an older Java version. Here's how to target older Java versions in NetBeans: Target JDK for Java Applications.
You are running your program incorrectly. You need to do
java friendspro.Server.RunServer -ORBIniti ...
in your main directory (probably bin or src).
On your computer, open CMD, cd to your source directory and then, as Banthar specified,
java friendpro.Server.RunServer ...

Categories

Resources