Linux class not found

PSR-4 autoloader Fatal error: Class not found

However if I try and create a new User() , I get the error Fatal error: Class ‘User’ not found in /var/www/public/api/v1/index.php on line 8 Looking at the composer autoload_psr4.php file it looks ok: // autoload_psr4.php @generated by Composer

$vendorDir = dirname(dirname(__FILE__)); $baseDir = dirname(dirname($vendorDir)); return array( 'XdgBaseDir\\' => array($vendorDir . '/dnoegel/php-xdg-base-dir/src'), 'Monolog\\' => array($vendorDir . '/monolog/monolog/src/Monolog'), 'KeenIO\\' => array($vendorDir . '/keen-io/keen-io/src'), 'Bix\\' => array($baseDir . '/src'), ); 

1 Answer 1

First of all, Linux (I’m not sure which PC you use) is case-sensitive. In your autoloading, you defined src/bix , while it is src/Bix .

But more importantly, with PSR-4, the specified namespace prefix is not included in the directory structure (to avoid directories containing just one directory). In your case, if you configure «Bix\\»: «src/» , a class Bix\Model\User should be located in src/Model/User.php .

EDIT: You’re misunderstanding PHP namespaces. In PHP, you’re not saying «import everything from Bix\Model into the global namespace for this file» with use Bix\Model; . Instead, it means: «Alias Model in this file to Bix\Model «.

require_once "vendor/autoload.php"; use Bix\Model; $user = new Model\User(); 
require_once "vendor/autoload.php"; use Bix\Model\User; $user = new User(); 

Источник

Class Not Found exception with exec-maven-plugin when run on Linux

I am trying to run TestNG tests. My Project organization is — src->test->java->com->shn->library The below command works well in Windows but fails in Linux.

mvn -X clean exec:java -Dexec.mainClass="com.shn.library.RunSuitesInParallel" -Dexec.classpathScope=test -e 
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on project UAF: An exception occured while executing the Java class. com.shn.library.RunSuitesInParallel -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on project UAF: An exception occured while executing the Java class. com.shn.library.RunSuitesInParallel at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59) at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196) at org.apache.maven.cli.MavenCli.main(MavenCli.java:141) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352) Caused by: org.apache.maven.plugin.MojoExecutionException: An exception occured while executing the Java class. com.shn.library.RunSuitesInParallel at org.codehaus.mojo.exec.ExecJavaMojo.execute(ExecJavaMojo.java:352) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209) . 19 more Caused by: java.lang.ClassNotFoundException: com.shn.library.RunSuitesInParallel 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:423) at java.lang.ClassLoader.loadClass(ClassLoader.java:356) at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:285) at java.lang.Thread.run(Thread.java:722) [ERROR] [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException 

Источник

Читайте также:  Менеджер виртуальных машин astra linux настройка

laravel class not found (works on localhost but not on DO server)

This is a repeat question — eg: Laravel 4 migrations — class not found However, I’ve tried every solution (from every forum I could find) and cannot figure this out.

Scenario

I created a Laravel 4 project on my local machine — added some classes, controllers, views, etc — the project works great. I then copy this fresh repo onto my DO server — install dependencies with composer, etc. The project looks good, except for one page that shouts an error:

Class 'company' not found Symfony\Component\Debug\Exception\FatalErrorException …/­vendor/­laravel/­framework/­src/­Illuminate/­Database/­Eloquent/­Model.php593 

I’ve tried.

I’ve updated composer. I’ve tried «dump-autoload». I changed the ‘minimum-stability’ to ‘stable’ in the composer.json file (yes, this was a proposed solution on a forum post). Other solutions have to do with adding «psr-4» or «psr-0» into the composer.json file depending on the composer version — tried both. What boggles my mind about this the most, is that this page works great on my local machine, but not on the DO server. If you guys need more info about something to fish this answer out, just let me know. Any help is appreciated 🙂 this is what my composer.json file looks like:

< "name": "laravel/laravel", "description": "The Laravel Framework.", "keywords": ["framework", "laravel"], "license": "MIT", "require": < "laravel/framework": "4.0.*" >, "autoload": < "classmap": [ "app/commands", "app/controllers", "app/models", "app/database/migrations", "app/database/seeds", "app/tests/TestCase.php" ] >, "scripts": < "post-install-cmd": [ "php artisan optimize" ], "post-update-cmd": [ "php artisan clear-compiled", "php artisan optimize" ], "post-create-project-cmd": [ "php artisan key:generate" ] >, "config": < "preferred-install": "dist" >, "minimum-stability": "stable" > 

Источник

Cannot find main class on Linux — Classpath issue

I am having some trouble running a few jar’s on a linux box. Basically, I am getting an error saying it cannot find the main class of my main jar. The class is defenetly present so it must be a classpath issue. I am not great with linux, so I am looking for some advice as to where I might be missing something. First off, I am setting the classpath in the users bash_profile; adding all the jar’s required, seperated by a : delimeter. I then export the classpath. Then, in the shell (ksh) script I use to invoke the main jar, I also st the classpath and call it in the command using -cp so it looks like:

TEST_ROOTDIR = /Test/app CLASSPATH=$CLASSPATH:$/lib/myjar.jar . export CLASSPATH CMD_STRING="java -Xms200m -Xmx200m -XX:MaxPermSize=200m -verbose -cp $CLASSPATH" CMD_STRING="$CMD_STRING " nohup $CMD_STRING > $OUTPUT_FILE 

The output file shows all the jre jar’s getting executed, it then loads the jar and throws a class not found exception for the main class. I am stumped, any help would be greatly appreciated

Читайте также:  Linux ubuntu on raspberry pi

i’d rather start without all the fancy nohup and variable-thingies; first try getting it to run on the cmdline, e.g. -Xms200m -Xmx200m -XX:MaxPermSize=200m -verbose -cp /Test/app/lib/myjar.jar myjar . once this works, put it into the script.

obviously the cmdline should include the java-interpreter itself: java -Xms200m -Xmx200m -XX:MaxPermSize=200m -verbose -cp /Test/app/lib/myjar.jar myclass (and myclass being your

— which you haven’t given)

Источник

OpenJDK 11: Getting ClassNotFound on Linux, works fine on windows

We have a desktop-based swing app running fine with Oracle JDK 1.8. After moving to OpenJDK 11 we got some not found exceptions for classes com.sun.java.swing.Painter , we resolved that by generating a bundled jar that contains some classes of com.sun.java.swing.Painter.java and some 4-5 classes and added it by

java --patch-module java.desktop=custombundle.jar -classpath path_of_jars starter_class* 

Now everything works fine with AdoptOpenJDK11 or OpenJDK11 on Windows systems. But on Linux (Ubuntu-64 bits or any ARM-based Linux environments) we got another class not found/No class def exception related to class com.sun.java.swing.plaf.windows.WindowsLookAndFeel from the third-party libraries we used. We can not remove the calls to com.sun.java.swing.plaf.windows.WindowsLookAndFeel because they are in 3rd party libs. The company providing the libs and also other forum sites suggest adding:

--add-exports java.desktop/com.sun.java.swing.plaf.windows=ALL-UNNAMED* 
java --add-exports java.desktop/com.sun.java.swing.plaf.windows=ALL-UNNAMED --patch-module java.desktop=custombundle.jar -classpath path_of_jars starter_class* 
WARNING: package com.sun.java.swing.plaf.windows not in java.desktop 

and we got still the class not found exceptions for com.sun.java.swing.plaf.windows.WindowsLookAndFeel I tried java.desktop/com.sun.java.swing.plaf.gtk instead of java.desktop/com.sun.java.swing.plaf.windows , the warning disappeared but still not working. Any suggestions? Adopt OpenJDK version: latest (11.0.8.10) Ubuntu: 20.04 (recent) Note: Swing Issue on Java 10 did not help

Источник

Оцените статью
Adblock
detector