简体   繁体   English

Java可以在“绝对”路径下正常运行,而不在指定CLASSPATH下运行

[英]java runs fine with 'absolute' path, doesn't run with CLASSPATH specified

my program is in package pl.edu.uj.tcs.crazySocket; 我的程序在package pl.edu.uj.tcs.crazySocket; due to some requirements. 由于某些要求。 I work in the crazySocket directory. 我在crazySocket目录中工作。 In order to compile the program I use command 为了编译程序,我使用命令

CLASSPATH=~/prog/colosseum/data javac tictactoe.java

and that succeeds. 那成功了。 I want to run the program. 我要运行程序。 I change javac to java and get rid of the '.java'. 我将javac更改为java,并摆脱了“ .java”。 I get 我懂了

Exception in thread "main" java.lang.NoClassDefFoundError: tictactoe
Caused by: java.lang.ClassNotFoundException: tictactoe
        at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:266)

when I get up in the tree directory to the ~/prog/colosseum/data and run java pl/edu/uj/tcs/crazySocket/tictactoe all works fine. 当我在树目录中找到〜/ prog / colosseum / data并运行java pl/edu/uj/tcs/crazySocket/tictactoe一切正常。

What's wrong with the CLASSPATH? CLASSPATH有什么问题? Shouldn't it work both with javac and java? 它不能同时与javac和java一起使用吗?

There's nothing wrong with your classpath, it's your call to java that's wrong. 您的类路径没有错,是您对java的调用错了。

You need to specify the full qualified class name pl.edu.uj.tcs.crazySocket.tictactoe . 需要指定完整的合格类名称pl.edu.uj.tcs.crazySocket.tictactoe

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java程序运行正常但不编译 - Java program runs fine but doesn't compile 从 .classpath 中删除绝对依赖路径; 相对路径不起作用 - remove absolute dependency path from `.classpath`; relative path doesn't work 当我在 VSCode 中运行时程序运行良好,但是 package maven 扩展构建不运行 - Program runs fine when I run in VSCode, but the package the maven extension builds doesn't run JavaFX应用程序在IntelliJ中运行Main时运行良好,内置jar无法运行 - JavaFX application runs fine when running Main in IntelliJ, built jar doesn't run 错误:尝试运行JAR时无法找到或加载主类Main。 Manifest和classpath看起来很好,仍然无法正常工作? - Error: Could not find or load main class Main when trying to run JAR. Manifest and classpath look fine, still doesn't work? 动态Web项目不会整体在tomcat上运行,但是.java可以在服务器上运行。 为什么? - Dynamic web project won't run on tomcat as a whole but .java runs on server just fine. Why? 从类路径,绝对路径,包括“ ../ ..”路径的相对路径中读取Java中的文件 - Read a file in Java from classpath, absolute path, relative path that includes “../..” path 为什么指定的类路径找不到扩展类? - Why the specified classpath doesn't find the extended class? Java 不要运行主文件(类路径) - Java don't run the main file (classpath) Java程序可以在Eclipse中正常运行,但不能作为.jar文件运行(配置路径错误吗?) - Java program runs fine in Eclipse but not as a .jar file (Is the config path wrong??)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM