Java won't compile for me
hi. I'm new to Java. Installed JAva from a book's CD. Java1.3. When I compile, I get an error message saying "bad command or file name". It doesn't compile. Thank goodness for the book's exercises being on CD. The .class files are already there, whichmeans the .java files were already compiled, yes? (i'm new) So, running Java with these already compiled files works fine. It's just compiling that is the problem. I suspect it has something to do with my settings in my autoexec.bat file, but what do i know? I'm new!
Can somebody help me out?
I can't keep checking this forum yet, so i'd prefer to be emailed at [email protected]
Thanks, Christian
this is the first version of my autoexec.bat file that i tried:
@ECHO OFF
SET PATH=C:\IBMTOOLS
If Exist C:\MFGBOOTI.REG C:\WINDOWS\REGEDIT C:\MFGBOOTI.REG
PATH=%PATH%;"C:\Program Files\Mts"
PATH C:\jdk1.3.0_02\bin;%PATH%
SET CLASSPATH=%CLASSPATH%;.;C:\jdk1.3.0_02\lib\tools.jar
this is the second version :
@ECHO OFF
SET PATH=C:\IBMTOOLS
If Exist C:\MFGBOOTI.REG C:\WINDOWS\REGEDIT C:\MFGBOOTI.REG
PATH=%PATH%;"C:\Program Files\Mts"
PATH C:\jdk1.3.0_02\bin;%PATH%
SET CLASSPATH=%CLASSPATH%;.;C:\jdk1.3.0_02\lib\tools.jar;C:\j21work
Similar Messages
-
Java 2 SDK compilator for beginners
Hi to all here.
I am really sorry to disturb you all,
I am beginner in Java and I need to download Java 2 SDK compilator in order to compile my homeworks. I went lost in all the reliese EE, SE and so on I saw in Sun homepage.
Which one is the right one ?
I have Windows Vista Home edition in my computer.
Thanks for helping me.
FlavioDownload and install a Java SE 6 JDK for your Windows platform which is available here:
http://java.sun.com/javase/downloads/index.jsp
If you want some GUI Application you may choose the version containing NetBeans, if you only want the compiler and runtime environment install the first option (JDK 6 Update 4).
Edited by: mezler on Feb 20, 2008 2:13 PM -
Evaluator.java won't compile due to issues with javax.tools.*
* Evaluator.java
* Created on January 23, 2007, 4:17 PM
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
package ObjectTools;
import java.io.*;
import java.net.*;
import javax.tools.*;
import java.lang.reflect.*;
* Utilizes {@link java.lang.reflect} package
* @author ppowell-c
public abstract class Evaluator {
public static boolean writeSource(final String sourcePath, final String sourceCode)
throws FileNotFoundException {
PrintWriter writer = new PrintWriter(sourcePath);
writer.println(sourceCode);
writer.close();
return true;
public static boolean compile(final String sourcePath) throws IOException {
final JavaCompilerTool compiler = ToolProvider.defaultJavaCompiler();
final JavaFileManager manager = compiler.getStandardFileManager();
final JavaFileObject source =
manager.getFileForInput(sourcePath); /* java.io.IOException */
final JavaCompilerTool.CompilationTask task = compiler.run(null, source);
return task.getResult();
public static final java.lang.Class loadExpression(final String path, final String className)
throws MalformedURLException,
ClassNotFoundException { /* java.net.MalformedURLException */
final URLClassLoader myLoader = new URLClassLoader(new java.net.URL[] {
new File(path).toURI().toURL()
/* java.lang.ClassNotFoundException */
return Class.forName(className, true, myLoader);
public static java.lang.Object evalExpression(final Class test)
throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
final Class[] parameterType = null;
/* java.lang.NoSuchMethodException */
final Method method = test.getMethod("expression", parameterType);
final Object[] argument = null;
Object instance = null;
/* java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException */
return method.invoke(instance, argument);
public static Object eval(final String expression)
throws FileNotFoundException, IOException, MalformedURLException,
ClassNotFoundException, NoSuchMethodException, IllegalAccessException,
InvocationTargetException {
final Object result;
final String path = "c:/";
final String className = "ExpressionWrapper";
final String sourcePath = path + className + ".java";
writeSource(/* to */ sourcePath,
"public class " + className + "\n" +
"{ public static java.lang.Object expression()\n" +
" { return " + expression + "; }}\n" );
if(compile(sourcePath)) {
final Class class_ =
loadExpression(/* from */ path, className);
result = evalExpression(class_);
} else {
result = null;
return result;
}Produces compiler errors on javax.tools.ToolProvider along with nearly everything else in javax.tools to boot.
I'm using J2SE 1.5.0 with NetBeans 5.5 so they all should be there. I'm following the example at http://userpage.fu-berlin.de/~ram/pub/pub_jf47ht9Ht/evaluating-expressions-with-java since all I want to do is come up with a Java equivalent of "eval()", which I use in PHP whenever I need it.
Help appreciated, I'm lost here.
Thanx
PhilHow do you do the Java equivalent of eval()?The language provides no support for that.
Reflection lets you call any method, where you
specify that method's name as a string and go through
a few other steps to build the proper Method object
with the proper args.
(http://java.sun.com/docs/books/tutorial/reflect/) It
won't let you just evaluate Java source code as a
script interpreter though. To do that, see
www.beanshell.org. Jython and I think Ruby on Rails
also give you scriptingin Java. Jython uses Python's
syntax, but gives you access to your Java classes. I
don't know ayhthing about RoR.I am going to look up PHP/Java myself as I know no Python right offhand (but probably could learn it in about 10,000 years). Tried to figure out reflection but couldn't figure out how to do what in PHP we do like this:
$msg = eval('JButton ' . $nameArray[$i][0] . ' = new JButton("' . $nameArray[$i][1] . '");'); -
Tinyos won't compile for 'tinynode' target using the msp430 toolchain
Meanwhile, trying to compile Blink example for tinynode:
[takeda@takeda Blink]$ make tinynode
mkdir -p build/tinynode
compiling BlinkAppC to a tinynode binary
ncc -o build/tinynode/main.exe -Os -Os -mdisable-hwmul -mstrict-align -fnesc-separator=__ -Wall -Wshadow -Wnesc-all -target=tinynode -fnesc-cfile=build/tinynode/app.c -board= -DDEFINED_TOS_AM_GROUP=0x22 -DIDENT_APPNAME=\"BlinkAppC\" -DIDENT_USERNAME=\"takeda\" -DIDENT_HOSTNAME=\"takeda\" -DIDENT_USERHASH=0x3831b7f8L -DIDENT_TIMESTAMP=0x4e84bf69L -DIDENT_UIDHASH=0x4131c4c7L -fnesc-dump=wiring -fnesc-dump='interfaces(!abstract())' -fnesc-dump='referenced(interfacedefs, components)' -fnesc-dumpfile=build/tinynode/wiring-check.xml BlinkAppC.nc -lm
nesc1: invocation of msp430-gcc to find builtin macros failed (error message output follows)
Using built-in specs.
Reading specs from /usr/lib/gcc/msp430/4.5.3/../../../../msp430/lib/msp430mcu.spec
COLLECT_GCC=msp430-gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/msp430/4.5.3/lto-wrapper
Target: msp430
Configured with: /home/takeda/sfw/gcc-msp430/src/gcc-4.5.3/configure --prefix=/usr --infodir=/usr/share/info --mandir=/usr/share/man --disable-libssp --disable-nls --target=msp430 --enable-languages=c,c++ --with-gnu-as --with-gnu-ld --with-as=/usr/bin/msp430-as --with-ld=/usr/bin/msp430-ld --with-pkgversion=mspgcc_20110716
Thread model: single
gcc version 4.5.3 (mspgcc_20110716)
COLLECT_GCC_OPTIONS='-v' '-E' '-dM' '-mdisable-hwmul' '-mstrict-align' '-mmcu=msp430f1611' '-mcpu=430' '-mmpy=16' '-mivcnt=16' '-mcpu=430' '-mmpy=16' '-mivcnt=16'
/usr/libexec/gcc/msp430/4.5.3/cc1 -E -quiet -v -imultilib mmpy-16 -D__MSP430F1611__ /dev/null -mcpu=430 -mcpu=430 -mmpy=16 -mmpy=16 -mivcnt=16 -mivcnt=16 -mdisable-hwmul -mstrict-align -mmcu=msp430f1611 -mcpu=430 -mmpy=16 -mivcnt=16 -mcpu=430 -mmpy=16 -mivcnt=16 -dM
cc1: error: unrecognized command line option "-mstrict-align"
ignoring nonexistent directory "/usr/lib/gcc/msp430/4.5.3/../../../../msp430/sys-include"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/msp430/4.5.3/include
/usr/lib/gcc/msp430/4.5.3/include-fixed
/usr/lib/gcc/msp430/4.5.3/../../../../msp430/include
End of search list.
cc1: warning: -mdisable-hwmul deprecated, use -mmpy=none
nesc1: internal error: couldn't define builtin macros - exiting
make: *** [exe0] Error 1
[takeda@takeda Blink]$
Last edited by takeda (2011-09-29 19:00:51)in file /opt/tinyos-2.1.1/support/make/tinynode.target i've done for the moment the following
# mod_by_takeda
PFLAGS += -mmpy=none
# PFLAGS += -mdisable-hwmul
# mod_by_takeda
# PFLAGS += -mstrict-align
and now a very simple project compiles. (like a helloword app).
I geuss i am gonna have problems later.. -
ColdFusion 10 mod_jk won't compile for Apache HTTPD 2.4.6
Making all in apache-2.0
make[1]: Entering directory `./src/connector-source/native/apache-2.0'
./apr/build-1/libtool --silent --mode=compile gcc -std=gnu99 -I./httpd/include -DHAVE_CONFIG_H -DUSE_APACHE_MD5 -I ../common -I /include -I /include/unix -DLINUX -D_REENTRANT -D_GNU_SOURCE -g -O2 -pthread -DHAVE_APR -I./apr/include/apr-1 -I./apu/include/apr-1 -DHAVE_CONFIG_H -g -O2 -pthread -DLINUX -D_REENTRANT -D_GNU_SOURCE -c mod_jk.c -o mod_jk.lo
mod_jk.c: In function 'init_ws_service':
mod_jk.c:832: error: 'conn_rec' has no member named 'remote_ip'
mod_jk.c:833: error: 'conn_rec' has no member named 'remote_addr'
mod_jk.c:1106: error: 'conn_rec' has no member named 'remote_ip'
mod_jk.c:1106: error: 'conn_rec' has no member named 'remote_ip'
make[1]: *** [mod_jk.lo] Error 1
make[1]: Leaving directory `./src/connector-source/native/apache-2.0'
make: *** [all-recursive] Error 1Re: when will ColdFusion 10 (or higher) support apache 2.4?
-
I used the javac command in dos mode to compile my .java files , but in my recent program i have so many errors that they dont fit into the dos screen(in dos mode i cannot move up and down!).
Is there any simple compiler for windows(or GUI) that could solve my problem?If you haven't done this already you can right click on your Dos Prompt icon and go to properties, then go to Screen, then change the initial size of your prompt to the largest it will go, (50 lines I think). That might give you a little more room...
-
Robohelp for Word won't compile
Hi,I've been trying to get one of my projects to work in Robohelp for Word. But the minute I create a second topic the compiled doen't work. there are no errors. the compilation just never starts. This also happens when I rename the first topic to something else.
I have the following configurations:
Robphelp for Word 7 build 145
MS Office Work 2007
windows XP professional with service pack 3
I have deleted and started the project from scratch several times without any success. Any help would be highly appreciated
Thanks
EdnaHi,
Thanks for your reply. The problem is there even with tutorial files and dummy projects.
It seems that there is a problem with saving the document. If I don’t add anything the projects will compile problery. But the minute I change something it won't compile. When I want to close the word document I get a meesage saying if I would like Robohelp to save the document. If I press on "yes" nothing happens. If I press on "yes to all" nothing happens. Pressing on "no" closes the document.
I have setup my word 2007 in a way so it will save .doc formats instead of .docx. But either way it makes no different the problem is with both file formats. -
Can anyone tell me where i can get an compiler for the mac os x?
if you have downloaded the latest java release from apple (using the update module) you should have java 1.5 by now... On a mac you can compile using the terminal...
voyx -
Error of compilation for an IOS project:
Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded
at adobe.abc.Algorithms$SetMap.get(Algorithms.java:226)
at adobe.abc.Algorithms$ExprWorkQueue.add(Algorithms.java:491)
at adobe.abc.Algorithms$ExprWorkQueue.addAll(Algorithms.java:524)
at adobe.abc.GlobalOptimizer.sccp_analyze(GlobalOptimizer.java:6007)
at adobe.abc.GlobalOptimizer.sccp(GlobalOptimizer.java:4733)
at adobe.abc.GlobalOptimizer.optimize(GlobalOptimizer.java:3615)
at adobe.abc.GlobalOptimizer.optimize(GlobalOptimizer.java:2309)
at adobe.abc.LLVMEmitter.optimizeABCs(LLVMEmitter.java:534)
at adobe.abc.LLVMEmitter.generateBitcode(LLVMEmitter.java:343)
at com.adobe.air.ipa.GOAOTCompiler.convertAbcToLlvmBitcodeImpl(GOAOTCompiler.java:243)
at com.adobe.air.ipa.BitcodeGenerator.main(BitcodeGenerator.java:85)
Compilation failed while executing : ADT
We allocate 4GB of memory for the compilator and the results is the same. The build is very long (~5 min)See if this helps
OutOfMemoryError: GC overhead limit exceeded when heap is just fine
regards
Pravin -
How do I set javac to compile for older versions of java?
I need to compile a ".java" file for version 1.4.0 of java in order to run it on Nintendo DS. However, my version of java is 1.6.0.
In resume, I need to set javac to compile for version 1.4.0, but I haven't had much success figuring it out myself, so if anyone knows this, please?WalterLaan wrote:
Note that you want to compile against the 1.4 libraries (rt.jar) as well to avoid NoSuchClass/MethodsErrors with the [ -bootclasspath option|http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javac.html#crosscomp-options]
++++ that.
Using the -source/-target options are not a guarantee that the specified JRE will have the required classes, methods and attributes available. Those options only ensure the classes have a format that is 'reabable' by the target JRE.
Using the -bootclasspath option guarantees the classes are not only readable, but that the VM will not throw 'NoSuchMethodError's or equivalent, at run-time. -
This is my first in depth attempt to understand the code for enabling arrays. I THINK I have a fairly simple problem, but the code won't compile and NetBeans is telling me I'm missing a symbol &/or class, which I just don't get. Here is the code for the Inventory1 module as well as the main module - what am I not seeing?
Inventory1 module
import java.util.Scanner;
import static java.lang.System.out;
public class Inventory1
//declare and initialize variables
int[] itemNumber = new int [5];
String[] productName = new String[5];
int[] stockAmount = new int[5];
double[] productCost = new double[5];
double[] totalValue = new double[5];
int i;
//int i = 0;
//initialize scanner
Scanner sc = new Scanner(System.in);
Inventory1 info = new Inventory1
public void inventoryInput()
while (int i = 0; i < 5; i++)
out.println("Please enter item number: "); //prompt - item number
info.itemNumber[i] = sc.nextInt(); // input
out.println( "Enter product name/description: "); //prompt - product name
info.productName[i] = sc.nextLine(); // input
out.println("Quantity in stock: "); // prompt - quantity
int temp = sc.nextInt(); // capture temp number to verify
if( temp <=0 )
{ // ensure stock amount is positive number
out.println( "Inventory numbers must be positive. Please" +
"enter a correct value." ); // prompt for correct #
temp = sc.nextInt(); // exit if statement
else info.stockAmount[i] = temp; // input
out.println("What is the product cost for each unit? "); // prompt - cost
double temp2 = sc.nextDouble();
if( temp <=0 )
out.println( "Product cost must be a positive dollar " +
"amount. Please enter correct product cost." );
temp2 = sc.nextDouble();
else info.productCost[i] = temp2;
out.println( "We hope this inventory program was helpful. Thank you for " +
"using our program." );
} // end method inventoryInput
}main module
public class Main {
public static void main(String[] args) { //start main method
Inventory1 currentInventory = new Inventory1(); //call Inventory class
currentInventory.inventoryInput();
}init:
deps-jar:
Compiling 1 source file to C:\Documents and Settings\Tammy\My Documents\School\JavaProgramming\Inventory\build\classes
C:\Documents and Settings\Tammy\My Documents\School\JavaProgramming\Inventory\src\inventory\Inventory1.java:28: '(' or '[' expected
public void inventoryInput()
C:\Documents and Settings\Tammy\My Documents\School\JavaProgramming\Inventory\src\inventory\Inventory1.java:30: '.class' expected
while (int i = 0; i < 5; i++)
C:\Documents and Settings\Tammy\My Documents\School\JavaProgramming\Inventory\src\inventory\Inventory1.java:30: illegal start of type
while (int i = 0; i < 5; i++)
C:\Documents and Settings\Tammy\My Documents\School\JavaProgramming\Inventory\src\inventory\Inventory1.java:30: not a statement
while (int i = 0; i < 5; i++)
C:\Documents and Settings\Tammy\My Documents\School\JavaProgramming\Inventory\src\inventory\Inventory1.java:30: ';' expected
while (int i = 0; i < 5; i++)
5 errors
BUILD FAILED (total time: 0 seconds) -
i have 3 java files that im trying to compile for my CS class:
IntCalc.java
IntCalcPanel.java
IntCalcGUI.java
the panel uses IntCalc for an object and the GUI uses the panel as an object.
i cannot compile the panel or the GUI in the command prompt because it says
IntegerCalculatorPanel.java:17: cannot find symbol
symbol : class IntegerCalculator
location: class IntegerCalculatorPanel
IntegerCalculator calc = new IntegerCalculator();
^
IntegerCalculatorPanel.java:17: cannot find symbol
symbol : class IntegerCalculator
location: class IntegerCalculatorPanel
IntegerCalculator calc = new IntegerCalculator();
^
2 errors
even though all three files are in the same directory
these files WILL compile if i use an IDE. i tried jGRASP and they compile and run fine.
what do i do to fix this?
(xp pro)For classpath, you can shorten the word to "-cp", I
believe (it doesn't work on our Java at work, becauseNo, that will not work in this case!
-cp only works on the java command (to execute Java programs), not on javac (the compiler). Stupid, isn't it?
Make sure that your CLASSPATH environment variable is not set - that will make Java use the current directory as the default, and you won't have to type "-classpath ." every time.
If you're starting a serious project with lots of source files, I suggest you have a look at Ant to manage your build process. -
This project used to compile for me on a different computer. That computer is gone now, and I've moved the project to a new computer. I have not changed anything at all about the project, but when I try to build it now, I get 3,626 error messages that start off with this:
cd /Users/jesse/VersionControl/JaCK3/trunk/c++/fmbridge
/usr/bin/gcc-4.0 -x c++-header -arch ppc -pipe -Wno-trigraphs -fpascal-strings -fasm-blocks -Os -fmessage-length=0 -mtune=G5 -fvisibility-inlines-hidden -mmacosx-version-min=10.4 -I/Users/jesse/VersionControl/JaCK3/trunk/c++/fmbridge/build/JaCK3.build/Deploy ment/version8lib.build/version8lib.hmap -F/Users/jesse/VersionControl/JaCK3/trunk/c++/fmbridge/build/Deployment -F/Users/jesse/VersionControl/JaCK3/trunk/c++/fmbridge/../Libraries -I/Users/jesse/VersionControl/JaCK3/trunk/c++/fmbridge/build/Deployment/include -I/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks -I/Users/jesse/VersionControl/JaCK3/trunk/c++/fmbridge/build/JaCK3.build/Deploy ment/version8lib.build/DerivedSources -isysroot /Developer/SDKs/MacOSX10.4u.sdk -c /System/Library/Frameworks/Carbon.framework/Headers/Carbon.h -o /Library/Caches/com.apple.Xcode.1028/SharedPrecompiledHeaders/Carbon-hadzljfzkp pjveajhqnujmgoizvu/Carbon.h.gch
/System/Library/Frameworks/Carbon.framework/Headers/Carbon.h:20:39: error: CoreServices/CoreServices.h: No such file or directory
/System/Library/Frameworks/Carbon.framework/Headers/Carbon.h:24:53: error: ApplicationServices/ApplicationServices.h: No such file or directory
In file included from /System/Library/Frameworks/Carbon.framework/Frameworks/HIToolbox.framework/Head ers/HIToolbox.h:25,
from /System/Library/Frameworks/Carbon.framework/Headers/Carbon.h:29:
/System/Library/Frameworks/Carbon.framework/Frameworks/HIToolbox.framework/Heade rs/HIObject.h:24:43: error: CoreFoundation/CoreFoundation.h: No such file or directory
In file included from /System/Library/Frameworks/Carbon.framework/Frameworks/HIToolbox.framework/Head ers/HIToolbox.h:33,
from /System/Library/Frameworks/Carbon.framework/Headers/Carbon.h:29:
/System/Library/Frameworks/Carbon.framework/Frameworks/HIToolbox.framework/Heade rs/HIGeometry.h:20:39: error: CoreGraphics/CoreGraphics.h: No such file or directory
etc....Jesse Barnum wrote:
Sorry, I appreciate your help and should have thought more carefully about offending people.
No offense taken. It is just that many people who post here only do so out of frustration and really only want to rant. They are unwilling to step back and take a more logical and reasoned look at a problem. I'm not going to bother reading rants, but I will be glad to help anyone who will meet me halfway.
However, I deeply dislike XCode, for numerous reasons:
I'm pretty ambivalent about Xcode. I've seen better and worse IDEs. It would probably be better if there were some competition around, but Metrowerks put themselves out of business.
Xcode certainly has its faults, but what you have described is not behavior that I have experienced or that I have ever heard about.
*This same exact project compiled fine on another computer (which unfortunately has been wiped clean)
I have to say I'm skeptical about this. How do I (or you) know that there wasn't some fix not checked in to SCM on the other machine? Or some change that didn't work but did wind up in SM?
*I'm able to build successfully on Leopard, just not my computer running Tiger. However, when I do the build on Leopard, it won't run on Tiger (I get missing link errors at runtime), even though I specify 10.4 as the target SDK.
One way to narrow down where the problem might be is to build a test application on each system and make sure that works properly. How do I know you aren't one of those people who tried to pick and choose which parts of Xcode to install? You must install all of Xcode.
How do I know you haven't tried to run one of those nasty apps like Monolingual that strips out resources that "you don't need"?
*When I do the build in Tiger with 'current operating system' specified as the SDK, I get a completely about 800 error messages.
That indicates that either your project or Xcode installation is completely broken. The first thing to do is find out which one of those it is.
When I specify 10.4 as the SDK (which seems to me like it should be the same behavior as 'current operating system', since the machine is running 10.4), I get about 3,000 error messages as stated in my original post.
Given that you don't seem to be able to build anything, trying a cross-platform built is unlikely to work better. The 10.4u SDK is for building a Universal binary (PPC and x86).
*It is very difficult for me to figure out where to change various settings, since some are at the project level, some are at the target level, and some are at the build configuration level. Sometimes when I double-click on a target to change its settings, I get a blank editable text area; other times I get a GUI with modifiable target settings. In other words, I find the UI to be extremely difficult to manage.
Those are certainly valid complaints. Once you get past this initial problem of building, it might be a good idea to post one or more new threads about how to use Xcode more effectively.
In fact, when I've had to change certain settings in the past, it's faster for me to modify the project file in a text editor than to hunt for that particular GUI widget.
Given that you seem uncomfortable with Xcode, this seems like a pretty dangerous thing to do. You could easily wreck your project so that it stops building for mysterious reasons.
I'm much more comfortable with Java and IntelliJ than I am with C++ and XCode, so I'm sure that is a big part of my problem, but my gut reaction to the problems that I'm having right now is "don't breathe wrong on XCode or it will stop working and you have to recreate the project". That is why I don't like it (to put it mildly).
You normally shouldn't have to recreate projects just to get Xcode working. However, that might be what you need to do in this case. If you can definitively prove that Xcode is correctly installed - by building a set of simple 10.4, 10.5 and 10.4u applications, then your project must be corrupted.
Again, I appreciate your help. I only posted this rant to explain my previous post, which I should have kept to myself.
I know how you feel. I got someone else mad at me in another thread when I called pthreads "pathetic" -
FtpClient client.delete("file") won't compile?
Hello Fine People,
I have this ftp program that is working, except for the delete command:
import sun.net.ftp.*;
import sun.net.*;
String server = "192.168.0.0";
String user = "me";
String passwd = "mypassword";
FtpClient client = new FtpClient();
client.openServer(server);
client.login(user, passwd);
TelnetInputStream tis = null;
client.binary();
client.cd("Composites");
tis = client.list();
client.get("filename");
client.delete("filename");
This is roughly how it is. Without the last line, it compiles and runs fine. But when I add the client.delete line, it won't compile and gives this error:
ImageTransfer.java:229: cannot resolve symbol
symbol : method delete (java.lang.String)
location: class sun.net.ftp.FtpClient
client.delete("filename");
Please help!
- LoganYes. The class you should be importing is, obviously, FTPClient. But don't waste your time trying to compile what is clearly just a code fragment example. The article lists several sources of FTP client software. Once you have chosen one package to evaluate, write your test program using the actual classes from that package, using its API documentation for guidance.
-
I have had success in one of my servlets using JavaMail. I was able to send an email to my inbox to test it out. I proceeded to create another servlet based on that 1st one, and for reasons I can't explain, the servlet won't compile.
I get this error.
cannot resolve symbol :
variable : RecipientType
location : java.lang.String
msg.setRecipient(Message.RecipientType.TO, to); I get the same error when I switch out setRecipient for addRecipient.
However, through further testing, I've found that not only does my 1st servlet still compile, but I'm also able to run the code from the 2nd servlet, successfully in a JSP page. This is driving me nuts...how could there be a problem compiling? There's no reason why one servlet compiles (with similar if not almost exactly the same code) and the other won't. Plus this runs fine in a JSP page...what's going on??? I've spent hours on this and I can't figure it out...please help, any input is appreciated.
Here is the JSP page that runs successfully :
<%@page import="java.io.*"%>
<%@page import="java.util.Properties"%>
<%@page import="javax.mail.*"%>
<%@page import="javax.mail.Message.RecipientType"%>
<%@page import="javax.mail.internet.*"%>
<%@page import="javax.servlet.*"%>
<%@page import="javax.servlet.http.*"%>
<%@page import="javax.naming.*"%>
<%@page import="javax.sql.*"%>
<%@page import="java.sql.*"%>
<%
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
Context ctx = new InitialContext();
if(ctx == null )
throw new Exception("Boom - No Context");
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/myDB");
conn = ds.getConnection();
stmt = conn.createStatement();
//get the POP3 and SMTP property values from db
rs = stmt.executeQuery("Select Tech_Support_Email, POP3, SMTP from sitewide_info");
String hostemailaddress = "";
String POP3 = ""; //mail.smtp.host, this one 1st
String SMTP = ""; //smtp.stratos.net, this one 2nd
if(rs.next()) {
hostemailaddress = rs.getString(1);
POP3 = rs.getString(2);
SMTP = rs.getString(3);
// Specify the SMTP Host
Properties props = new Properties();
//POP3 = mail.smtp.host & SMTP = smtp.stratos.net - must be in this order
props.put(POP3, SMTP);
// Create a mail session
Session ssn = Session.getDefaultInstance(props, null);
ssn.setDebug(true);
String subject = "Testing out Email";
String body = "hello";
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
rs = stmt.executeQuery("Select Customer_Name, Email_Address from customer_profiles where "
+"Customer_Number=1111");
String fromName = "";
String fromEmail = "";
if(rs.next()) {
fromName = rs.getString(1);
fromEmail = rs.getString(2);
InternetAddress from = new InternetAddress(fromEmail,fromName);
String toName = "Bob";
InternetAddress to = new InternetAddress(hostemailaddress,toName);
// Create the message
Message msg = new MimeMessage(ssn);
msg.setFrom(from);
msg.addRecipient(Message.RecipientType.TO, to);
msg.setSubject(subject);
msg.setContent(body, "text/html");
Transport.send(msg);
}//try
catch (MessagingException mex) {
mex.printStackTrace(); }
catch(Exception e) {}
finally {
try {
if (rs!=null) rs.close();
catch(SQLException e){}
try {
if (stmt!=null) stmt.close();
catch(SQLException e){}
try {
if (conn!=null) conn.close();
catch(SQLException e){}
}//finally
%>
Here's the servlet that won't compile :
package testing.servlets.email;
import java.io.*;
import java.util.Properties;
import javax.mail.*;
import javax.mail.Message.RecipientType;
import javax.mail.internet.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.naming.*;
import javax.sql.*;
import java.sql.*;
public class MessageCenterServlet extends HttpServlet {
public Connection conn = null;
public Statement stmt = null;
public Statement stmt2 = null;
public ResultSet rs = null;
public ResultSet rss = null;
public PrintWriter out = null;
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
doPost(req,res);
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
try {
out = res.getWriter();
Context ctx = new InitialContext();
if(ctx == null )
throw new Exception("Boom - No Context");
DataSource ds =
(DataSource)ctx.lookup(
"java:comp/env/jdbc/myDB");
conn = ds.getConnection();
stmt = conn.createStatement();
stmt2 = conn.createStatement();
HttpSession session = req.getSession();
String Subject = (String)session.getAttribute("Subject");
String Message = (String)session.getAttribute("Message");
sendAnEmail(rs,stmt,Subject,Message,res);
}//try
catch (Exception e) { }
finally { cleanup(rs,rss,stmt,stmt2,conn); }
}//post
public void cleanup(ResultSet r, ResultSet rs, Statement s, Statement s2, Connection c){
try {
if (r!=null) r.close();
catch(SQLException e){}
try {
if (rs!=null) rs.close();
catch(SQLException e){}
try {
if (s!=null) s.close();
catch(SQLException e){}
try {
if (s2!=null) s2.close();
catch(SQLException e){}
try {
if (c!=null) c.close();
catch(SQLException e){}
}//cleanUp
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public void sendAnEmail(ResultSet rs, Statement stmt, String Subject,String Message, HttpServletResponse res) {
try {
//get the POP3 and SMTP property values from db
rs = stmt.executeQuery("Select Tech_Support_Email, POP3, SMTP from sitewide_info");
String hostemailaddress = "";
String POP3 = "";
String SMTP = "";
if(rs.next()) {
hostemailaddress = rs.getString(1);
POP3 = rs.getString(2);
SMTP = rs.getString(3);
// Specify the SMTP Host
Properties props = new Properties();
props.put(POP3, SMTP);
// Create a mail session
Session ssn = Session.getDefaultInstance(props, null);
ssn.setDebug(true);
String subject = "Testing out Email";
String body = "hello";
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
rs = stmt.executeQuery("Select Customer_Name, Email_Address from customer_profiles where "
+"Customer_Number=1111");
String fromName = "";
String fromEmail = "";
if(rs.next()) {
fromName = rs.getString(1);
fromEmail = rs.getString(2);
InternetAddress from = new InternetAddress(fromDealerEmail,fromDealerName);
String toName = "Bob";
InternetAddress to = new InternetAddress(hostemailaddress,toName);
// Create the message
Message msg = new MimeMessage(ssn);
msg.setFrom(from);
msg.setRecipient(Message.RecipientType.TO, to);
msg.setSubject(subject);
msg.setContent(body, "text/html");
Transport.send(msg);
}//try
catch (MessagingException mex) {
mex.printStackTrace(); }
catch(Exception e) {}
}//end
}//class -Love2Java
Edited by: Love2Java on Mar 11, 2008 9:15 PMI have similar problem
I have the below code in Eclipse and I was able to compile and run it and everything works fine...
but I have code over in Oracle Jdev and jdev is complaining that "Message.RecipientType.TO" is not found....
I do have all the jars in the class path.... can't figure out what's wrong
can some one plz help me out.
import java.util.Date;
import java.util.Properties;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.mail.util.ByteArrayDataSource;
public void postMail( String recipients, String subject,
String message , String from) throws MessagingException
boolean debug = false;
//Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.host", "server");
props.put("mail.smtp.auth", "true");
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getDefaultInstance(props, auth);
session.setDebug(debug);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients, false));
// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
private class SMTPAuthenticator extends javax.mail.Authenticator
public PasswordAuthentication getPasswordAuthentication()
String username ="user";
String password = "pass";
return new PasswordAuthentication(username, password);
}
Maybe you are looking for
-
RH 11: Conditional Build tags applied: Content still showing up in search
Hello. I am generating WebHelp using conditional build tags using RH 11. I have marked books in the TOC with a CBT of Not in 6.1. I generated help and excluded content marked with the CBT Not in 6.1. When the Web Help is generated, the books marked w
-
I have an applet in a jar to sign it for that applet access local files; but i don't know how to call the applet(in the .jar) from the jsp. Thanks in Advanced.
-
Purchasing new HP Photosmart printer which will require new OS X Mountain Lion driver, which installation steps do I take. Old printer still on iMac.
-
OBIEE 11g EVALUATE function working fine with Administrator but
Hi, We have a report with EVALUATE function , which is working fine with Administrator User but when we run for other users its giving following error. State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occur
-
Report Authorization issues after Authorization Migration in BI 7.0
Hi SAPians, we are facing report access for the customers after migration of authorizations (3.x to 7.0). All these are Customer reports and need to restrict their customer codes only. In two ways, i have tried to resolved this. 1. Roles - Maintained