I'm trying to compile a project with javac in windows, but I'm getting a "package x does not exist" error.
Even if the jar file containing them is in the classpath.
Here is the command, I just added line returns to make it readable:
javac
-d bin
-sourcepath src
-cp
.;
lib/gson-2.5.jar;
lib/jruby-complete-9.1.2.0.jar;
lib/lwjgl-platform-2.9.3-natives-windows.jar;
lib/lwjgl-platform-2.9.3-natives-linux.jar;
lib/lwjgl-platform-2.9.3-natives-osx.jar;
lib/jinput-platform-2.0.5-natives-windows.jar;
lib/jinput-platform-2.0.5-natives-linux.jar;
lib/jinput-platform-2.0.5-natives-osx.jar;
lib/lwjgl.jar;
lib/lwjgl_util.jar;
lib/jorbis-0.0.17.jar;
lib/jinput-2.0.5.jar;
lib/gdx-platform-1.9.2-natives-desktop.jar;
lib/gdx-controllers-platform-1.9.2-natives-desktop.jar;
lib/gdx-freetype-platform-1.9.2-natives-desktop.jar;
lib/gdx-1.9.2.jar;lib/gdx-backend-lwjgl-1.9.2.jar;
lib/gdx-controllers-1.9.2.jar;
lib/gdx-controllers-desktop-1.9.2.jar;
lib/gdx-freetype-1.9.2.jar;
lib/jlayer-1.0.1-gdx.jar;
lib/jutils-1.0.0.jar
src/com/azias/awbe/Launcher.java
And here is the error message:
src\com\azias\awbe\Launcher.java:3: error: package com.badlogic.gdx.backends.lwjgl does not exist
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
^
src\com\azias\awbe\Launcher.java:4: error: package com.badlogic.gdx.backends.lwjgl does not exist
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
^
src\com\azias\awbe\Launcher.java:16: error: cannot find symbol
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
^
symbol: class LwjglApplicationConfiguration
location: class Launcher
src\com\azias\awbe\Launcher.java:16: error: cannot find symbol
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
^
symbol: class LwjglApplicationConfiguration
location: class Launcher
src\com\azias\awbe\Launcher.java:27: error: cannot find symbol
new LwjglApplication(new AdvanceWarsBootleg(), config);
^
symbol: class LwjglApplication
location: class Launcher
src\com\azias\awbe\AdvanceWarsBootleg.java:3: error: package com.badlogic.gdx does not exist
import com.badlogic.gdx.Game;
^
src\com\azias\awbe\AdvanceWarsBootleg.java:4: error: package com.badlogic.gdx.graphics.g2d does not exist
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
^
src\com\azias\awbe\AdvanceWarsBootleg.java:6: error: cannot find symbol
public class AdvanceWarsBootleg extends Game {
^
symbol: class Game
src\com\azias\awbe\AdvanceWarsBootleg.java:7: error: cannot find symbol
public SpriteBatch batch;
^
symbol: class SpriteBatch
location: class AdvanceWarsBootleg
src\com\azias\awbe\AdvanceWarsBootleg.java:9: error: method does not override or implement a method from a supertype
#Override
^
src\com\azias\awbe\AdvanceWarsBootleg.java:17: error: method does not override or implement a method from a supertype
#Override
^
src\com\azias\awbe\AdvanceWarsBootleg.java:19: error: cannot find symbol
super.render();
^
symbol: variable super
location: class AdvanceWarsBootleg
12 errors
Using Java 6 or later, the classpath option supports wildcards. Note the following:
Use straight quotes (")
Use *, not *.jar
so you could simplify your javac statement:
javac
-d bin
-sourcepath src
-cp ".;libs/*"
src/com/azias/awbe/Launcher.java
Also depending on the platform the separator is ; (windows) or : (unix).
Related
What im trying to do is to run my expo project on native code with expo run:android command(since firebase cannot run on expo)
When I run the expo run:android it shows me this error:
error: cannot find symbol
import io.invertase.firebase.RNFirebasePackage;
^
symbol: class RNFirebasePackage
location: package io.invertase.firebase
C:\Users\use\Desktop\BeMySafety\android\app\src\main\java\alcoders\bemysafety\MainApplication.java:24: error: package io.invertase.firebase.notifications does not exist
import io.invertase.firebase.notifications.RNFirebaseNotificationsPackage;
^
C:\Users\use\Desktop\BeMySafety\android\app\src\main\java\alcoders\bemysafety\MainApplication.java:40: error: cannot find symbol
packages.add(new RNFirebaseMessagingPackage());
^
symbol: class RNFirebaseMessagingPackage
C:\Users\use\Desktop\BeMySafety\android\app\src\main\java\alcoders\bemysafety\MainApplication.java:41: error: cannot find symbol
packages.add(new RNFirebaseNotificationsPackage());
^
symbol: class RNFirebaseNotificationsPackage
Note: C:\Users\use\Desktop\BeMySafety\android\app\src\debug\java\alcoders\bemysafety\ReactNativeFlipper.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
4 errors
MainApplication.java
protected List<ReactPackage> getPackages() {
#SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
// Packages that cannot be autolinked yet can be added manually here, for example:
packages.add(new RNFirebaseMessagingPackage());
packages.add(new RNFirebaseNotificationsPackage());
return packages;
}
How can I solve this error?
I have downloaded junit-4.10.jar and hamcrest-2.2.jar to a folder C:/JUnit.
In Environment Variables->System Variables I Have set JUNIT_HOME as C:\JUnit and CLASSPATH as %CLASSPATH%;%JUNIT_HOME%\junit-4.10.jar;.;
Then I created a folder C:/JUNIT_WORKSPACE and added two files TestJunit.java and TestRunner.java.
Now in command line terminal when I enter:
C:\JUNIT_WORKSPACE>javac TestJunit.java TestRunner.java
It throws the below error:
C:\JUNIT_WORKSPACE>javac TestJunit.java TestRunner.java
TestJunit.java:1: error: package org.junit does not exist
import org.junit.Test;
^
TestJunit.java:2: error: package org.junit does not exist
import static org.junit.Assert.assertEquals;
^
TestJunit.java:2: error: static import only from classes and interfaces
import static org.junit.Assert.assertEquals;
^
TestRunner.java:1: error: package org.junit.runner does not exist
import org.junit.runner.JUnitCore;
^
TestRunner.java:2: error: package org.junit.runner does not exist
import org.junit.runner.Result;
^
TestRunner.java:3: error: package org.junit.runner.notification does not exist
import org.junit.runner.notification.Failure;
^
TestJunit.java:5: error: cannot find symbol
#Test
^
symbol: class Test
location: class TestJunit
TestJunit.java:9: error: cannot find symbol
assertEquals("Junit is working fine",str);
^
symbol: method assertEquals(String,String)
location: class TestJunit
TestRunner.java:7: error: cannot find symbol
Result result = JUnitCore.runClasses(TestJunit.class);
^
symbol: class Result
location: class TestRunner
TestRunner.java:7: error: cannot find symbol
Result result = JUnitCore.runClasses(TestJunit.class);
^
symbol: variable JUnitCore
location: class TestRunner
TestRunner.java:9: error: cannot find symbol
for (Failure failure : result.getFailures()) {
^
symbol: class Failure
location: class TestRunner
11 errors
What did I do wrong here? I assume I have set the HOME and Classpath correctly.
The issue is resolved.
I changed the CLASSPATH to %CLASSPATH%;.;%JUNIT_HOME%\junit-4.10.jar;%JUNIT_HOME%\hamcrest-core-2.2.jar;
and after that on running the commands in cmd, I get the correct response:
C:\JUNIT_WORKSPACE>javac TestJunit.java TestRunner.java
C:\JUNIT_WORKSPACE>java TestRunner
true
C:\JUNIT_WORKSPACE>
I want to compile my java class like that: javac ResultSet.java
But I get the following error:
ResultSet.java:5: error: package data does not exist
import data.Spieler;
^
ResultSet.java:8: error: cannot find symbol
private ArrayList<Spieler> meineSpieler = new ArrayList<Spieler>();
^
symbol: class Spieler
location: class ResultSet
ResultSet.java:12: error: cannot find symbol
public native Spieler[] getSpieler();
^
symbol: class Spieler
location: class ResultSet
ResultSet.java:18: error: cannot find symbol
public ArrayList<Spieler> getMeineSpieler() {
^
symbol: class Spieler
location: class ResultSet
ResultSet.java:8: error: cannot find symbol
private ArrayList<Spieler> meineSpieler = new ArrayList<Spieler>();
^
symbol: class Spieler
location: class ResultSet
How can I import the spieler class? Should I set the classpath or is there a other way to fix that?
Go one directory up and then compile it with
javac data/JNIResultSet.java
Update:
Ok, your class JNIResultSet is in package model and it uses other classes in package data.
Then your compile command should be as follows:
javac -cp . model/JNIResultSet.java
The -cp . part means, that your classpath includes the current directory. This is the root of your package hierarchy. So the compiler can find the *.java files in package data and compiles them also as needed.
You see, this can be very complicated. For more classes this will be nearly unmanageable. So you should really consider to use a build system like Ant, Maven or Gradle.
use -classpath while compiling the file as
javac -classpath <path-to-dependent-classes> JNIResultSet.java
It is required only when the Spieler is not on classpath!
for more help refer javac oracle documentation
I am following exercise 1.2 of the Oracle Java SE 8 exam preparation which instructs me to build a main class GreetingsUniverse and three classes which will be initialised by the main class; Mars, Earth and Venus.
I have the com directory stored at location: C:\Users\Chris\Documents\JavaMM
package com.ocajexam.tutorial;
import com.ocajexam.tutorial.planets.Earth;
import com.ocajexam.tutorial.planets.Venus;
import com.ocajexam.tutorial.planets.Mars;
public class GreetingsUniverse
{
public static void main (String[] args)
{
System.out.println("Greetings, Universe!");
Earth e = new Earth();
Mars m = new Mars();
Venus v = new Venus();
}
}
package com.ocajexam.tutorial.planets;
public class Mars
{
public Mars()
{
System.out.println("Hello from Mars!");
}
}
package com.ocajexam.tutorial.planets;
public class Earth
{
public Earth()
{
System.out.println("Hello from Earth!");
}
}
package com.ocajexam.tutorial.planets;
public class Venus
{
public Venus()
{
System.out.println("Hello from Venus!");
}
}
The exercise aim is to determine the command line arguments required to compile the code.
I have the GreetingsUniverse java file stored in com\ocajexam\tutorial\ and the planets store in com\ocajexam\tutorial\planets
I have tried various solutions with no success:
javac -d . -cp com\ocajexam\tutorial\planets com\ocajexam\tutorial\GreetingsUniverse.java
javac -d . -cp com com\ocajexam\tutorial\GreetingsUniverse.java
I keep getting the following error:
C:\Users\Chris\Documents\JavaMM>javac -d . -cp com com\ocajexam\tutorial\GreetingsUniverse.java
com\ocajexam\tutorial\GreetingsUniverse.java:8: error: cannot find symbol
Earth e = new Earth();
^
symbol: class Earth
location: class GreetingsUniverse
com\ocajexam\tutorial\GreetingsUniverse.java:8: error: cannot find symbol
Earth e = new Earth();
^
symbol: class Earth
location: class GreetingsUniverse
com\ocajexam\tutorial\GreetingsUniverse.java:9: error: cannot find symbol
Mars m = new Mars();
^
symbol: class Mars
location: class GreetingsUniverse
com\ocajexam\tutorial\GreetingsUniverse.java:9: error: cannot find symbol
Mars m = new Mars();
^
symbol: class Mars
location: class GreetingsUniverse
com\ocajexam\tutorial\GreetingsUniverse.java:10: error: cannot find symbol
Venus v = new Venus();
^
symbol: class Venus
location: class GreetingsUniverse
com\ocajexam\tutorial\GreetingsUniverse.java:10: error: cannot find symbol
Venus v = new Venus();
^
symbol: class Venus
location: class GreetingsUniverse
6 errors
Does anyone know where I am going wrong with this?
I have also tried the following which produces a different error message:
C:\Users\Chris\Documents\JavaMM>javac -d . com\ocajexam\tutorial\planets\Earth.java;com\ocajexam\tutorial\planets\Mars.java;com\ocajexam\tutorial\planets\Venus.java com\ocajexam\tutorial\GreetingsUniverse.java
Produces this error:
javac: file not found: com\ocajexam\tutorial\planets\Earth.java;com\ocajexam\tutorial\planets\Mars.java;com\ocajexam\tutorial\planets\Venus.java
Usage: javac <options> <source files>
use -help for a list of possible options
The files are definitely there, if I dir on the planets directory I can see them there:
Directory of C:\Users\Chris\Documents\JavaMM\com\ocajexam\tutorial\planets
16/10/2016 11:33 <DIR> .
16/10/2016 11:33 <DIR> ..
15/10/2016 21:48 135 Earth.java
15/10/2016 21:48 132 Mars.java
15/10/2016 21:48 135 Venus.java
Update:
After further debugging this is just getting stranger..
I am trying to compile only the planet files using the first half of the command:
javac -d . -cp com\ocajexam\tutorial\planets\*.java
When I check the planet directory, only two of the planets have compiled. When I remove the java class that isn't compiling, only 1 of the files is compiled!
When I use the same command specifying the java file I want to compile:
javac -d . -cp com\ocajexam\tutorial\planets\Venus.java
I get the following error:
javac: no source files
Usage: javac <options> <source files>
use -help for a list of possible options
I can't make any sense of this because Venus.java was one of the files that did compile when I ran the /*.java compilation command to detect any java files in the directory
You need to compile all the classes first. The javac only compiles your main class. Use javac -cp /path/to/file/*.java. The asterisk (*.java) means to compile all java classes in the folder.
The example in the OCA Java SE 8 Programmer I Study Guide uses a constructor without parentheses.
package com.ocajexam.tutorial.planets;
public class Earth {
public Earth {
System.out.println("Hello from Earth!");
}
}
this should, of course, be
package com.ocajexam.tutorial.planets;
public class Earth {
public Earth () {
System.out.println("Hello from Earth!");
}
}
You can then run javac com/ocajexam/tutorial/greetingsUniverse.java and java com/ocajexam/tutorial/GreetingsUniverse.
Although strictly speaking this is not an answer to the question (which uses constructors with parentheses), it might help other people with the same error.
All of the .java files used need to be on the classpath. ie javac -d . -cp com com\ocajexam\tutorial\*.java com\ocajexam\tutorial\planets\*.java
Try doing: javac -d . -cp com com/ocajexam/tutorial/GreetingsUniverse.java com/ocajexam/tutorial/planets/Earth.java com/ocajexam/tutorial/planets/Mars.java com/ocajexam/tutorial/planets/Venus.java
I have 2 classes
CLASS1 (the main class)
- calls threading glass
CLASS2 (the threading class)
- calls function
- calls json.simple.jar functons
and a .JAR (https://code.google.com/p/json-simple/)
jar/json.simple.jar
Now the main problem is that i actualy managed to make both classes to compile with those commands
javac -d . -cp '.:jar/json.simple.jar' *.java;
this will create a folder named package1 and then when i try to run it it gives me the error
java javanolo.CLASS1 -jar 'jar/json.simple.jar';
Selected (9) IPS ... <-- this is the first **println**
Exception in thread "main" java.lang.NoClassDefFoundError: org/json/simple/parser/ParseException
at javanolo.CLASS1.main(CLASS1.java:70)
Caused by: java.lang.ClassNotFoundException: org.json.simple.parser.ParseException
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:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
and i assume this is because it is not finding some of the json simple functions. Why that? I've imported them
// json encode/decode
import org.json.simple.JSONValue;
import org.json.simple.JSONObject;
import org.json.simple.parser.ParseException;
and i am sure that i have imported the .jar, because if i run
javac -d . *.java;
error :
import org.json.simple.JSONValue;
^
CLASS1.java:14: error: package org.json.simple does not exist
import org.json.simple.JSONObject;
^
CLASS1.java:15: error: package org.json.simple.parser does not exist
import org.json.simple.parser.ParseException;
^
CLASS2.java:16: error: package org.json.simple does not exist
import org.json.simple.JSONValue;
^
CLASS2.java:17: error: package org.json.simple does not exist
import org.json.simple.JSONObject;
^
CLASS2.java:18: error: package org.json.simple.parser does not exist
import org.json.simple.parser.ParseException;
^
CLASS2.java:148: error: cannot find symbol
public Map<String,String> openAndGetGeoDataByProxy(String ip,String port,int timeout) throws IOException, InterruptedException, ParseException
^
symbol: class ParseException
location: class CLASS2
CLASS2.java:99: error: cannot find symbol
} catch (ParseException ex) {
^
symbol: class ParseException
location: class CLASS2
CLASS2.java:188: error: cannot find symbol
Object jsonObject = JSONValue.parse(line);
^
symbol: variable JSONValue
location: class CLASS2
CLASS2.java:191: error: cannot find symbol
JSONObject jsonArray = (JSONObject)jsonObject;
^
symbol: class JSONObject
location: class CLASS2
CLASS2.java:191: error: cannot find symbol
JSONObject jsonArray = (JSONObject)jsonObject;
^
symbol: class JSONObject
location: class CLASS2
CLASS2.java:194: error: cannot find symbol
JSONObject jsonArray2 = (JSONObject)jsonArray.get("array_result");
^
symbol: class JSONObject
location: class CLASS2
CLASS2.java:194: error: cannot find symbol
JSONObject jsonArray2 = (JSONObject)jsonArray.get("array_result");
^
symbol: class JSONObject
location: class CLASS2
so i know for sure that json-simple.jar is being used when compilation.
The main question is, how can i run CLASS1 and CLASS2 with that .jar file?
Why LINUX based system is so different then the WINDOWS NETBEANS? I mean java is platform independent ...
Ho can i connect NETBEANS to my server trough SFTP so i can code there directly.
Thanks.
EDIT TRIES
i have tried the following commands, none of them works, it gives me the message like i was running the java -help command
try1
java -cp .;jar/json.simple.jar javanolo.CLASS1
try2
java -cp .;'/root/folder/folder/jar/json.simple.jar' javanolo.CLASS1
try3
java -cp .;/root/folder/folder/jar/json.simple.jar javanolo.CLASS1
can anyone help me please (would be better on chat)? i really need this
With this:
java javanolo.CLASS1 -jar 'jar/json.simple.jar'
you run your class and give the rest of the command line, i.e. -jar jar/json.simple.jar as arguments.
What you want is:
java -cp .;jar/json.simple.jar javanolo.CLASS1
or, in a UNIX shell:
java -cp .:jar/json.simple.jar javanolo.CLASS1
Note that your class path is the same in compilation and execution.