0

I am using Eclipse with Eclipse Maven Plugin (m2e).

My java program compiles and run correctly from eclipse interface but I am unable to compile and run it from terminal.

My Eclipse Setting:

I am using two third party APIs, for which in eclipse build path I added

  1. "/home/syed/workspace/FirstMaven/target/resources/fuse-jna-master/build/classes" (as external class folder)
  2. "/home/syed/workspace/FirstMaven/target/resources/apache-jena-2.11.1/lib" (as external jars)

Package:

package org.organization.upesh.FirstMaven;

My Project path:

syed@ubuntu:~/workspace/FirstMaven$  

Source Code Directory Path:

syed@ubuntu:~/workspace/FirstMaven/src/main/java/org/organization/upesh/FirstMaven$

Classes Directory:

syed@ubuntu:~/workspace/FirstMaven/target/classes/org/organization/upesh/FirstMaven$ 

When I try to execute myProgram via below command

syed@ubuntu:~/workspace/FirstMaven/target/classes$ java org.organization.upesh.FirstMaven.myProgram

it gives me these errors:

Exception in thread "main" java.lang.NoClassDefFoundError: net/fusejna/util/FuseFilesystemAdapterFull
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
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:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
   Caused by: java.lang.ClassNotFoundException: net.fusejna.util.FuseFilesystemAdapterFull
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
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:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 13 more

But my test program that do not use the third party API runs correctly via:

syed@ubuntu:~/workspace/FirstMaven/target/classes$ java org.organization.upesh.FirstMaven.test

I think myProgram is not executing because of the two APIs (class folder and jar folder) that I am using.

I have added path of class and jar folders of the APIs to /etc/environment (given below) and rested my computer, but still the same error

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/syed/workspace/FirstMaven/target/resources/apache-jena-2.11.1/lib:/home/syed/workspace/FirstMaven/target/resources/fuse-jna-master/build/classes"

Please guide me how to run my program correctly

1 Answer 1

1

JVM does not get libraries from PATH. It uses special environment variable CLASSPATH that can contain a list of directories or jar files separated by colon on Unix or semicolon on Windows.

So, just define CLASSPATH and put references to all your libraries there.

Aleternatively (and IMHO better) use command line switch -classpath (or its alias -cp) when running java:

java -cp mylib1.jar:mylib2.jar com.mycompany.Main
Sign up to request clarification or add additional context in comments.

2 Comments

syed@ubuntu:~/workspace/FirstMaven/target/classes$ java org.organization.upesh.FirstMaven.SFS_360 gives the same error as mentioned in my question above and after including path as syed@ubuntu:~/workspace/FirstMaven/target/classes$ java -cp /home/syed/workspace/FirstMaven/target/resources/fuse-jna-master/build/classes org.organization.upesh.FirstMaven.SFS_360 it then gives new error Error: Could not find or load main class org.organization.upesh.FirstMaven.SFS_360
If your main class is in a jar, then the jar must be in the classpath. If it is a class file without being in a jar, then it must be in the directory that corresponds to its package, and the root directory for that package must be on the classpath.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.