Execution failed for task ':compileJava'. - Issue 3 in this series - java

Before this question gets closed for already being asked, as far as I can see it is a vague and common error so this is different from other questions.
I fixed the error in my previous post by installing a slightly different version of Forge, but have now reached Step 5 of this tutorial. When I use .\gradlew build with the example mod, everything seems to work fine (although I cannot find the console output) But when I edit the mod to how the author describes, I get many errors.
The example mod:
package com.example.examplemod;
import net.minecraft.init.Blocks;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
#Mod(modid = ExampleMod.MODID, version = ExampleMod.VERSION)
public class ExampleMod
{
public static final String MODID = "examplemod";
public static final String VERSION = "1.0";
#EventHandler
public void init(FMLInitializationEvent event)
{
// some example code
System.out.println("DIRT BLOCK >> "+Blocks.dirt.getUnlocalizedName());
}
}
How I changed it, following the tutorial:
package com.example.examplemod;
import net.minecraft.init.Blocks;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
#Mod(modid = ExampleMod.MODID, version = ExampleMod.VERSION)
public class ExampleMod
{
public static final String MODID = "examplemod";
public static final String VERSION = "1.1";
#EventHandler
public void init(FMLInitializationEvent event)
{
Block amethystOre = new ModBlock(Material.rock, "amethystOre");
GameRegistry.registerBlock(amethystOre, "amethystOre");
}
private class ModBlock extends Block
{
public ModBlock(Material material, String blockName)
{
super(material);
this.setBlockName(blockName);
this.setBlockTextureName(MODID + ":" + blockName);
this.setCreativeTab(CreativeTabs.tabBlock);
}
}
}
When I run .\gradlew build, I get:
#################################################
ForgeGradle 1.2-SNAPSHOT-fb514d3
https://github.com/MinecraftForge/ForgeGradle
#################################################
Powered by MCP unknown
http://modcoderpack.com
by: Searge, ProfMobius, Fesh0r,
R4wk, ZeuX, IngisKahn, bspkrs
#################################################
:compileApiJava UP-TO-DATE
:processApiResources UP-TO-DATE
:apiClasses UP-TO-DATE
:sourceMainJava UP-TO-DATE
:compileJava
warning: [options] bootstrap class path not set in conjunction with -source 1.6
C:\Users\benji\MinecraftWorkspace\forge-1.7.10-10.13.4.1558-1.7.10-src\build\sources\java\com\example\examplemod\ExampleMod.java:21: error: cannot find symbol
private class ModBlock extends Block
^
symbol: class Block
location: class ExampleMod
C:\Users\benji\MinecraftWorkspace\forge-1.7.10-10.13.4.1558-1.7.10-src\build\sources\java\com\example\examplemod\ExampleMod.java:23: error: cannot find symbol
public ModBlock(Material material, String blockName)
^
symbol: class Material
location: class ExampleMod.ModBlock
C:\Users\benji\MinecraftWorkspace\forge-1.7.10-10.13.4.1558-1.7.10-src\build\sources\java\com\example\examplemod\ExampleMod.java:17: error: cannot find symbol
Block amethystOre = new ModBlock(Material.rock, "amethystOre");
^
symbol: class Block
location: class ExampleMod
C:\Users\benji\MinecraftWorkspace\forge-1.7.10-10.13.4.1558-1.7.10-src\build\sources\java\com\example\examplemod\ExampleMod.java:17: error: cannot find symbol
Block amethystOre = new ModBlock(Material.rock, "amethystOre");
^
symbol: variable Material
location: class ExampleMod
C:\Users\benji\MinecraftWorkspace\forge-1.7.10-10.13.4.1558-1.7.10-src\build\sources\java\com\example\examplemod\ExampleMod.java:18: error: cannot find symbol
GameRegistry.registerBlock(amethystOre, "amethystOre");
^
symbol: variable GameRegistry
location: class ExampleMod
C:\Users\benji\MinecraftWorkspace\forge-1.7.10-10.13.4.1558-1.7.10-src\build\sources\java\com\example\examplemod\ExampleMod.java:26: error: cannot find symbol
this.setBlockName(blockName);
^
symbol: method setBlockName(String)
C:\Users\benji\MinecraftWorkspace\forge-1.7.10-10.13.4.1558-1.7.10-src\build\sources\java\com\example\examplemod\ExampleMod.java:27: error: cannot find symbol
this.setBlockTextureName(MODID + ":" + blockName);
^
symbol: method setBlockTextureName(String)
C:\Users\benji\MinecraftWorkspace\forge-1.7.10-10.13.4.1558-1.7.10-src\build\sources\java\com\example\examplemod\ExampleMod.java:28: error: cannot find symbol
this.setCreativeTab(CreativeTabs.tabBlock);
^
symbol: variable CreativeTabs
location: class ExampleMod.ModBlock
8 errors
1 warning
:compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
I don't know a whole lot about Java (I just started learning it) but I would assume that copying the tutorial character-for-character should result in an error-free program. Apparently not.
Looking at the error output on the compiler, the first error is 'The import net cannot be resolved' (line 3) I don't know why though.
Any help is much appreciated,
Ben

(From comment)
Import are wrong. You should use net.minecraft.* not net.minecraft.init.* :
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;

Related

How to compile an edited java file into a class class file that's a part of a package [Related to Minecraft]

So I have am trying to edit a class file that is in a .jar file (the .jar file has a few other classes but I am only trying to edit this one). I used the source .java for this specific class and I am having trouble compiling it into a class, because the compiler calls errors because it is calling things from the package.
Does anybody know what the problem is?
Alternatively, it would be really helpful if someone knew of a program that would allow me to directly edit the code of a .class file in a .jar file without all the decompiling and recompiling.
Extra information
The .jar file is a Minecraft mod I'm whipping up for a friend.
Code of original .class (which works):
package pw.cinque.cpsmod;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.common.gameevent.TickEvent$ClientTickEvent;
import net.minecraftforge.client.event.MouseEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import net.minecraftforge.client.event.MouseEvent;
import pw.cinque.cpsmod.CPSMod;
public class ClickListener
{
public ClickListener() {}
private boolean hasClickedThisTick = false;
#cpw.mods.fml.common.eventhandler.SubscribeEvent
public void onMouse(MouseEvent event) {
if (button != 0) {
return;
}
if ((CPSMod.preventDoubleclicks) && (buttonstate) && (hasClickedThisTick)) {
event.setCanceled(true);
return;
}
if (buttonstate) {
hasClickedThisTick = true;
CPSMod.addClick();
}
}
#cpw.mods.fml.common.eventhandler.SubscribeEvent
public void onClientTick(cpw.mods.fml.common.gameevent.TickEvent.ClientTickEvent event) {
hasClickedThisTick = false;
}
}
Code of file I edited:
package pw.cinque.cpsmod;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.common.gameevent.TickEvent$ClientTickEvent;
import net.minecraftforge.client.event.MouseEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import net.minecraftforge.client.event.MouseEvent;
import pw.cinque.cpsmod.CPSMod;
public class ClickListener {
private boolean hasClickedThisTick = false;
int newVar = 0;
#SubscribeEvent
public void onMouse(MouseEvent event) {
if (event.button != 0) {
return;
}
if (CPSMod.preventDoubleclicks && event.buttonstate && this.hasClickedThisTick) {
event.setCanceled(true);
return;
}
if (event.buttonstate)
{
this.hasClickedThisTick = true;
CPSMod.addClick();
newVar = CPSMod.getClicks();
if(newVar > 5)
{
CPSMod.addClick();
}
}
}
#SubscribeEvent
public void onClientTick(TickEvent.ClientTickEvent event) {
this.hasClickedThisTick = false;
}
}
These are the error messages I get when I try to compile it.
ClickListener.java:2: error: package cpw.mods.fml.common.eventhandler does not exist
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
^
ClickListener.java:3: error: package cpw.mods.fml.common.gameevent does not exist
import cpw.mods.fml.common.gameevent.TickEvent;
^
ClickListener.java:4: error: package cpw.mods.fml.common.gameevent does not exist
import cpw.mods.fml.common.gameevent.TickEvent$ClientTickEvent;
^
ClickListener.java:5: error: package net.minecraftforge.client.event does not exist
import net.minecraftforge.client.event.MouseEvent;
^
ClickListener.java:7: error: package cpw.mods.fml.common.eventhandler does not exist
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
^
ClickListener.java:8: error: package cpw.mods.fml.common.gameevent does not exist
import cpw.mods.fml.common.gameevent.TickEvent;
^
ClickListener.java:9: error: package net.minecraftforge.client.event does not exist
import net.minecraftforge.client.event.MouseEvent;
^
ClickListener.java:10: error: cannot find symbol
import pw.cinque.cpsmod.CPSMod;
^
symbol: class CPSMod
location: package pw.cinque.cpsmod
ClickListener.java:17: error: cannot find symbol
public void onMouse(MouseEvent event) {
^
symbol: class MouseEvent
location: class ClickListener
ClickListener.java:40: error: package TickEvent does not exist
public void onClientTick(TickEvent.ClientTickEvent event) {
^
ClickListener.java:16: error: cannot find symbol
#SubscribeEvent
^
symbol: class SubscribeEvent
location: class ClickListener
ClickListener.java:39: error: cannot find symbol
#SubscribeEvent
^
symbol: class SubscribeEvent
location: class ClickListener
ClickListener.java:21: error: cannot find symbol
if (CPSMod.preventDoubleclicks && event.buttonstate && this.hasClickedThisTick) {
^
symbol: variable CPSMod
location: class ClickListener
ClickListener.java:25: error: illegal start of type
if (event.buttonstate) {
^
ClickListener.java:27: error: cannot find symbol
CPSMod.addClick();
^
symbol: variable CPSMod
location: class ClickListener
ClickListener.java:28: error: cannot find symbol
gay = CPSMod.getClicks();
^
symbol: variable CPSMod
location: class ClickListener
ClickListener.java:33: error: cannot find symbol
CPSMod.addClick();
^
symbol: variable CPSMod
location: class ClickListener
17 errors
You need to compile that class with all its dependencies, otherwise it will not work. Probably you should get all the files from that .jar, make the modifications you want and then compile and compress it again.

Biojava: Package import errors

The following code:
import org.biojava.bio.structure.ResidueNumber;
import org.biojava.bio.structure.Structure;
import org.biojava.bio.structure.io.PDBFileReader;
import org.biojava3.protmod.structure.ProteinModificationIdentifier;
public class Test3 {
public static void main(String[] args) {
try {
PDBFileReader reader = new PDBFileReader();
reader.setAutoFetch(true);
// identify all modifications from PDB:1CAD and print them
String pdbId = "1CAD";
Structure struc = reader.getStructureById(pdbId);
Set<ModifiedCompound> mcs = identifyAllModfications(struc);
for (ModifiedCompound mc : mcs) {
System.out.println(mc.toString());
}
// identify all phosphosites from PDB:3MVJ and print them
pdbId = "3MVJ";
struc = reader.getStructureById(pdbId);
List<ResidueNumber> psites = identifyPhosphosites(struc);
for (ResidueNumber psite : psites) {
System.out.println(psite.toString());
}
} catch(Exception e) {
e.printStackTrace();
}
}
}
...results in the following stream of error messages:
C:\Users\CaitlinG>javac Test3.java
Test3.java:1: error: package org.biojava.bio.structure does not exist
import org.biojava.bio.structure.ResidueNumber;
^
Test3.java:2: error: package org.biojava.bio.structure does not exist
import org.biojava.bio.structure.Structure;
^
Test3.java:3: error: package org.biojava.bio.structure.io does not exist
import org.biojava.bio.structure.io.PDBFileReader;
^
Test3.java:4: error: package org.biojava4.protmod.structure does not exist
import org.biojava4.protmod.structure.ProteinModificationIdentifier;
^
Test3.java:9: error: cannot find symbol
PDBFileReader reader = new PDBFileReader();
^
symbol: class PDBFileReader
location: class Test3
Test3.java:9: error: cannot find symbol
PDBFileReader reader = new PDBFileReader();
^
symbol: class PDBFileReader
location: class Test3
Test3.java:14: error: cannot find symbol
Structure struc = reader.getStructureById(pdbId);
^
symbol: class Structure
location: class Test3
Test3.java:15: error: cannot find symbol
Set<ModifiedCompound> mcs = identifyAllModfications(struc)
^
symbol: class Set
location: class Test3
Test3.java:15: error: cannot find symbol
Set<ModifiedCompound> mcs = identifyAllModfications(struc)
^
symbol: class ModifiedCompound
location: class Test3
Test3.java:16: error: cannot find symbol
for (ModifiedCompound mc : mcs) {
^
symbol: class ModifiedCompound
location: class Test3
Test3.java:23: error: cannot find symbol
List<ResidueNumber> psites = identifyPhosphosites(struc);
^
symbol: class List
location: class Test3
Test3.java:23: error: cannot find symbol
List<ResidueNumber> psites = identifyPhosphosites(struc);
^
symbol: class ResidueNumber
location: class Test3
Test3.java:24: error: cannot find symbol
for (ResidueNumber psite : psites) {
^
symbol: class ResidueNumber
location: class Test3
13 errors
I have manually downloaded every jar file for Biojava 4.2.4 and stored each of them in a desktop folder (included in my classpath), listed each individually on my classpath, and stored both in C:\program files\java\jdk1.8.0_112\jre\lib\ext
and C:\program files\java\jdk1.8.0_112\jre\ext yet the errors are not resolved.
I'm using a Windows 10 machine, Java JDK8_112, and BioJava 4.2.4
Any help would be appreciated.
Thank you.

Compilation error when using Apache Thrift

I tried to run a thrift server and client program that was given in the thrift website and I got the below errors.Can anyone please help me out with the errors.
coding can be found in : https://thrift.apache.org/tutorial/java
naren#naren:~/Desktop$ javac javaserver.java
javaserver.java:16: error: class JavaServer is public, should be declared in a file named JavaServer.java
public class JavaServer {
^
javaserver.java:1: error: package org.apache.thrift.server does not exist
import org.apache.thrift.server.TServer;
^
javaserver.java:2: error: package org.apache.thrift.server.TServer does not exist
import org.apache.thrift.server.TServer.Args;
^
javaserver.java:3: error: package org.apache.thrift.server does not exist
import org.apache.thrift.server.TSimpleServer;
^
javaserver.java:4: error: package org.apache.thrift.server does not exist
import org.apache.thrift.server.TThreadPoolServer;
^
javaserver.java:5: error: package org.apache.thrift.transport does not exist
import org.apache.thrift.transport.TSSLTransportFactory;
^
javaserver.java:6: error: package org.apache.thrift.transport does not exist
import org.apache.thrift.transport.TServerSocket;
^
javaserver.java:7: error: package org.apache.thrift.transport does not exist
import org.apache.thrift.transport.TServerTransport;
^
javaserver.java:8: error: package org.apache.thrift.transport.TSSLTransportFactory does not exist
import org.apache.thrift.transport.TSSLTransportFactory.TSSLTransportParameters;
^
javaserver.java:11: error: package tutorial does not exist
import tutorial.*;
^
javaserver.java:12: error: package shared does not exist
import shared.*;
^
javaserver.java:18: error: cannot find symbol
public static CalculatorHandler handler;
^
symbol: class CalculatorHandler
location: class JavaServer
javaserver.java:20: error: package Calculator does not exist
public static Calculator.Processor processor;
^
javaserver.java:45: error: package Calculator does not exist
public static void simple(Calculator.Processor processor) {
^
javaserver.java:58: error: package Calculator does not exist
public static void secure(Calculator.Processor processor) {
^
javaserver.java:24: error: cannot find symbol
handler = new CalculatorHandler();
^
symbol: class CalculatorHandler
location: class JavaServer
javaserver.java:25: error: package Calculator does not exist
processor = new Calculator.Processor(handler);
^
javaserver.java:47: error: cannot find symbol
TServerTransport serverTransport = new TServerSocket(9090);
^
symbol: class TServerTransport
location: class JavaServer
javaserver.java:47: error: cannot find symbol
TServerTransport serverTransport = new TServerSocket(9090);
^
symbol: class TServerSocket
location: class JavaServer
javaserver.java:48: error: cannot find symbol
TServer server = new TSimpleServer(new Args(serverTransport).processor(processor));
^
symbol: class TServer
location: class JavaServer
javaserver.java:48: error: cannot find symbol
TServer server = new TSimpleServer(new Args(serverTransport).processor(processor));
^
symbol: class TSimpleServer
location: class JavaServer
javaserver.java:48: error: cannot find symbol
TServer server = new TSimpleServer(new Args(serverTransport).processor(processor));
^
symbol: class Args
location: class JavaServer
javaserver.java:61: error: cannot find symbol
TSSLTransportParameters params = new TSSLTransportParameters();
^
symbol: class TSSLTransportParameters
location: class JavaServer
javaserver.java:61: error: cannot find symbol
TSSLTransportParameters params = new TSSLTransportParameters();
^
symbol: class TSSLTransportParameters
location: class JavaServer
javaserver.java:65: error: cannot find symbol
TServerTransport serverTransport = TSSLTransportFactory.getServerSocket(9091, 0, null, params);
^
symbol: class TServerTransport
location: class JavaServer
javaserver.java:65: error: cannot find symbol
TServerTransport serverTransport = TSSLTransportFactory.getServerSocket(9091, 0, null, params);
^
symbol: variable TSSLTransportFactory
location: class JavaServer
javaserver.java:66: error: cannot find symbol
TServer server = new TSimpleServer(new Args(serverTransport).processor(processor));
^
symbol: class TServer
location: class JavaServer
javaserver.java:66: error: cannot find symbol
TServer server = new TSimpleServer(new Args(serverTransport).processor(processor));
^
symbol: class TSimpleServer
location: class JavaServer
javaserver.java:66: error: cannot find symbol
TServer server = new TSimpleServer(new Args(serverTransport).processor(processor));
^
symbol: class Args
location: class JavaServer
29 errors
naren#naren:~/Desktop$
As far as we can deduce from what you've shown, there's a couple of things that go wrong:
There seems to be an issue with your invocation of javac, it is missing a classpath that refers to the Apache Thrift library. You can specify the classpath using the -cp parameter. Make sure it points to the current directory, the Thrift libraries and any other libraries you might be using.
Your class JavaServer should be declared in a file named JavaServer.java (exactly as the compiler error says). Apparently, it's called javaserver.java, which is not the same (at least not on non-Windows platforms).
Sample .thrift files attached to official web tutorial have some errors (July 2015, v0.9.x).
Inconsequences in sample struct/classes etc, sample doesn't compile in few languages.
Version of this files in official tar.gz are good.

Compile java program on linux with external libraries

I am trying to compile a java file using SMACK for the XMPP libraries. In the folder of the java file i have included a Libs directory including all the *.jar files for SMACK but when i try
javac filename
i get this output:
SmackCcsClient.java:6: error: package org.jivesoftware.smack does not exist
import org.jivesoftware.smack.ConnectionConfiguration;
^
SmackCcsClient.java:7: error: package org.jivesoftware.smack.ConnectionConfiguration does not exist
import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode;
^
SmackCcsClient.java:8: error: package org.jivesoftware.smack does not exist
import org.jivesoftware.smack.ConnectionListener;
^
SmackCcsClient.java:9: error: package org.jivesoftware.smack does not exist
import org.jivesoftware.smack.PacketInterceptor;
^
SmackCcsClient.java:10: error: package org.jivesoftware.smack does not exist
import org.jivesoftware.smack.PacketListener;
^
SmackCcsClient.java:11: error: package org.jivesoftware.smack does not exist
import org.jivesoftware.smack.XMPPConnection;
^
SmackCcsClient.java:12: error: package org.jivesoftware.smack does not exist
import org.jivesoftware.smack.XMPPException;
^
SmackCcsClient.java:13: error: package org.jivesoftware.smack.filter does not exist
import org.jivesoftware.smack.filter.PacketTypeFilter;
^
SmackCcsClient.java:14: error: package org.jivesoftware.smack.packet does not exist
import org.jivesoftware.smack.packet.DefaultPacketExtension;
^
SmackCcsClient.java:15: error: package org.jivesoftware.smack.packet does not exist
import org.jivesoftware.smack.packet.Message;
^
SmackCcsClient.java:16: error: package org.jivesoftware.smack.packet does not exist
import org.jivesoftware.smack.packet.Packet;
^
SmackCcsClient.java:17: error: package org.jivesoftware.smack.packet does not exist
import org.jivesoftware.smack.packet.PacketExtension;
^
SmackCcsClient.java:18: error: package org.jivesoftware.smack.provider does not exist
import org.jivesoftware.smack.provider.PacketExtensionProvider;
^
SmackCcsClient.java:19: error: package org.jivesoftware.smack.provider does not exist
import org.jivesoftware.smack.provider.ProviderManager;
^
SmackCcsClient.java:20: error: package org.jivesoftware.smack.util does not exist
import org.jivesoftware.smack.util.StringUtils;
^
SmackCcsClient.java:21: error: package org.json.simple does not exist
import org.json.simple.JSONValue;
^
SmackCcsClient.java:22: error: package org.json.simple.parser does not exist
import org.json.simple.parser.ParseException;
^
SmackCcsClient.java:23: error: package org.xmlpull.v1 does not exist
import org.xmlpull.v1.XmlPullParser;
^
SmackCcsClient.java:52: error: cannot find symbol
XMPPConnection connection;
^
symbol: class XMPPConnection
location: class SmackCcsClient
SmackCcsClient.java:53: error: cannot find symbol
ConnectionConfiguration config;
^
symbol: class ConnectionConfiguration
location: class SmackCcsClient
SmackCcsClient.java:306: error: cannot find symbol
public void connect(String username, String password) throws XMPPException {
^
symbol: class XMPPException
location: class SmackCcsClient
SmackCcsClient.java:58: error: cannot find symbol
class GcmPacketExtension extends DefaultPacketExtension {
^
symbol: class DefaultPacketExtension
location: class SmackCcsClient
SmackCcsClient.java:77: error: cannot find symbol
public Packet toPacket() {
^
symbol: class Packet
location: class SmackCcsClient.GcmPacketExtension
SmackCcsClient.java:70: error: method does not override or implement a method from a supertype
#Override
^
SmackCcsClient.java:78: error: cannot find symbol
return new Message() {
^
symbol: class Message
location: class SmackCcsClient.GcmPacketExtension
SmackCcsClient.java:117: error: cannot find symbol
GCM_NAMESPACE, new PacketExtensionProvider() {
^
symbol: class PacketExtensionProvider
location: class SmackCcsClient
SmackCcsClient.java:116: error: cannot find symbol
ProviderManager.getInstance().addExtensionProvider(GCM_ELEMENT_NAME,
^
symbol: variable ProviderManager
location: class SmackCcsClient
SmackCcsClient.java:145: error: cannot find symbol
Packet request = new GcmPacketExtension(jsonRequest).toPacket();
^
symbol: class Packet
location: class SmackCcsClient
SmackCcsClient.java:276: error: cannot find symbol
return JSONValue.toJSONString(message);
^
symbol: variable JSONValue
location: class SmackCcsClient
SmackCcsClient.java:294: error: cannot find symbol
return JSONValue.toJSONString(message);
^
symbol: variable JSONValue
location: class SmackCcsClient
SmackCcsClient.java:307: error: cannot find symbol
config = new ConnectionConfiguration(GCM_SERVER, GCM_PORT);
^
symbol: class ConnectionConfiguration
location: class SmackCcsClient
SmackCcsClient.java:308: error: cannot find symbol
config.setSecurityMode(SecurityMode.enabled);
^
symbol: variable SecurityMode
location: class SmackCcsClient
SmackCcsClient.java:319: error: cannot find symbol
XMPPConnection.DEBUG_ENABLED = true;
^
symbol: variable XMPPConnection
location: class SmackCcsClient
SmackCcsClient.java:321: error: cannot find symbol
connection = new XMPPConnection(config);
^
symbol: class XMPPConnection
location: class SmackCcsClient
SmackCcsClient.java:324: error: cannot find symbol
connection.addConnectionListener(new ConnectionListener() {
^
symbol: class ConnectionListener
location: class SmackCcsClient
SmackCcsClient.java:353: error: cannot find symbol
connection.addPacketListener(new PacketListener() {
^
symbol: class PacketListener
location: class SmackCcsClient
SmackCcsClient.java:397: error: cannot find symbol
}, new PacketTypeFilter(Message.class));
^
symbol: class PacketTypeFilter
location: class SmackCcsClient
SmackCcsClient.java:397: error: cannot find symbol
}, new PacketTypeFilter(Message.class));
^
symbol: class Message
location: class SmackCcsClient
SmackCcsClient.java:400: error: cannot find symbol
connection.addPacketInterceptor(new PacketInterceptor() {
^
symbol: class PacketInterceptor
location: class SmackCcsClient
SmackCcsClient.java:405: error: cannot find symbol
}, new PacketTypeFilter(Message.class));
^
symbol: class PacketTypeFilter
location: class SmackCcsClient
SmackCcsClient.java:405: error: cannot find symbol
}, new PacketTypeFilter(Message.class));
^
symbol: class Message
location: class SmackCcsClient
SmackCcsClient.java:447: error: cannot find symbol
} catch (XMPPException e) {
^
symbol: class XMPPException
location: class SmackCcsClient
42 errors
how do i compile this correctly? is there some extra command needed for the smack library?
UPDATE:
i have created the following folder structure:
root
->bin
->src
->lib
I have tried compiling with different javac commands like:
javac -d bin -sourcepath src -cp :lib src/SmackCcsClient.java
I have tried various variations but i keep getting the same output every time.
UPDATE 2:
running the command:
javac -d bin -sourcepath src -cp lib/*.jar src/SmackCcsClient.java
gave the following output:
javac: invalid flag: lib/smack-android-4.1.1-javadoc.jar
Usage: javac <options> <source files>
use -help for a list of possible options
I am following different tutorials but i cannot figure out how to do this correctly.
A correct command would be (assuming all needed .jar files are actually in the lib/ folder, and all sources are in the src/ folder):
javac -d bin -sourcepath src -cp $(find lib -iname *.jar | xargs | tr " " ":") src/SmackCcsClient.java
The tricky part (within $( )) is building something like a.jar:b.jar:c.jar (no spaces, separated by :) from all the jar-files in the lib/ folder. Your attempt using -cp lib/*.jar failed because there were spaces instead of : separating the jar-files, and javac thought that the second jar-file it found was actually java source that you wanted to compile. And then complained that it did not know how to compile jar-files.
A simpler version (that relies on there being no sub-directories in lib/) is
javac -d bin -sourcepath src -cp $(echo lib/*.jar | tr " " ":") src/SmackCcsClient.java

How to properly compile this file using javac

I have the following file called Test.Java the code of which is
package example25;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.Iterator;
import org.jibx.runtime.BindingDirectory;
import org.jibx.runtime.IBindingFactory;
import org.jibx.runtime.IMarshallingContext;
import org.jibx.runtime.IUnmarshallingContext;
import org.jibx.runtime.JiBXException;
public class Test
{
public static void main(String[] args)
{
try
{
// unmarshal customer information from file
IBindingFactory bfact = BindingDirectory.getFactory(Order.class);
IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
FileInputStream in = new FileInputStream("D:\\Java Libraries\\jibx\\dwcode2\\starter.xml");
Order order = (Order)uctx.unmarshalDocument(in, null);
// compute the total amount of the order
float total = 0.0f;
for (Iterator<Item> iter = order.getItemList().iterator(); iter.hasNext();)
{
Item item = iter.next();
total += item.getPrice() * item.getQuantity();
}
order.setTotal(new Float(total));
// marshal object back out to file (with nice indentation, as UTF-8)
IMarshallingContext mctx = bfact.createMarshallingContext();
mctx.setIndent(2);
FileOutputStream out = new FileOutputStream("c:\\out.xml");
mctx.setOutput(out, null);
mctx.marshalDocument(order);
System.out.println("Processed order with " + order.getItemList().size() + " items and total value " + total);
}
catch (FileNotFoundException e)
{
e.printStackTrace();
System.exit(1);
} catch (JiBXException e)
{
e.printStackTrace();
System.exit(1);
}
}//end main
}//end class
Here is how i am trying to compile this file and the output that i get
C:\jibx\tutorial>javac example25\Test.java
example25\Test.java:8: error: package org.jibx.runtime does not exist
import org.jibx.runtime.BindingDirectory;
^
example25\Test.java:9: error: package org.jibx.runtime does not exist
import org.jibx.runtime.IBindingFactory;
^
example25\Test.java:10: error: package org.jibx.runtime does not exist
import org.jibx.runtime.IMarshallingContext;
^
example25\Test.java:11: error: package org.jibx.runtime does not exist
import org.jibx.runtime.IUnmarshallingContext;
^
example25\Test.java:12: error: package org.jibx.runtime does not exist
import org.jibx.runtime.JiBXException;
^
example25\Test.java:25: error: cannot find symbol
IBindingFactory bfact = BindingDirectory.getFactory(Order.class);
^
symbol: class IBindingFactory
location: class Test
example25\Test.java:25: error: cannot find symbol
IBindingFactory bfact = BindingDirectory.getFactory(Order.class);
^
symbol: variable BindingDirectory
location: class Test
example25\Test.java:26: error: cannot find symbol
IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
^
symbol: class IUnmarshallingContext
location: class Test
example25\Test.java:40: error: cannot find symbol
IMarshallingContext mctx = bfact.createMarshallingContext();
^
symbol: class IMarshallingContext
location: class Test
example25\Test.java:52: error: cannot find symbol
} catch (JiBXException e)
^
symbol: class JiBXException
location: class Test
10 errors
All the class files used by Test are present next to it and have been properly compiled.
Test is the last file that is giving me trouble. Furthermore some of the classes used in test are present in C:\jibx\lib> as opposed to C:\jibx\tutorial> from where i am executing commands. Any suggestions on how i cld resolve this issue without modifying my previously generated class files would be appreciated.
add the directory C:\jibx\lib to your classpath e.g.
SET CLASSPATH=%CLASSPATH%;C:\jibx\lib;.
and then do a javac
As there are some import errors set the class path properly as Satya said, And the your current class in some directory you should compile it with -d attribute of javac
As shown below
javac -d . YourfileName.java

Categories

Resources