This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with TextPad Classpath.

 
Cameron ax
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI, everyone. I want to import Html parser to TextPad.

I have found one web page for teach how to do this.
http://htmlparser.sourceforge.net/javadoc/doc-files/using.html

I have read it, but, I have not idea what to do with Textpad.
I am using Windows base system, Jdk1.6.0, and Textpad. That is all I have.

Any Help Will Be Appreciated
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15284
39
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

TextPad is just a text editor. As far as I know, it doesn't know anything about Java by itself. So, there's no way to import Java code in any way.

When you compile your code that uses the HTML parser library, you must specify that you're using the library by using the -classpath (or -cp) option on the command line. So, the command to compile your source code would become something like:

C:\MyProject> javac -cp C:\SomeDir\HtmlParser.jar com\mypackage\MyProgram.java

And to run it, you'd specify:

C:\MyProject> java -cp C:\SomeDir\HtmlParser.jar;. com.mypackage.MyProgram

Note: The ";." in the second command is to include the current directory "." into the classpath, because that's where Java is going to look for your own class com.mypackage.MyProgram.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48964
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving as would fit better in another forum. Not sure where.
 
Cameron ax
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:

C:\MyProject> javac -cp C:\SomeDir\HtmlParser.jar com\mypackage\MyProgram.java

And to run it, you'd specify:

C:\MyProject> java -cp C:\SomeDir\HtmlParser.jar;. com.mypackage.MyProgram

Note: The ";." in the second command is to include the current directory "." into the classpath, because that's where Java is going to look for your own class com.mypackage.MyProgram.


Thank you

and where should I post this command?

I tryed run this command in CMD,

set CLASSPATH=C:\lib\htmlparser.jar;C:\lib\htmllexer.jar;%CLASSPATH%
* I unziped lib folder, placed it in C Drive.

Somehow, it works. I guess it did change System Environment variable. I do not know if it is a appropriate way to do this.

I want to use html parser libraries to get the content between a html tag.

Is this a good way for doing this?
 
Campbell Ritchie
Sheriff
Pie
Posts: 48964
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should not set a CLASSPATH environment variable at all. If one already exists, it is probably a good idea to add a dot for current directory as its first entry.
What you are doing with the set command at the command line is setting a CLASSPATH for that particular command window. Which is a much better way to handle CLASSPATHs. You might do well to try . instead of %CLASSPATH% as its last entry, if there is no environment variable.
 
Cameron ax
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:You should not set a CLASSPATH environment variable at all. If one already exists, it is probably a good idea to add a dot for current directory as its first entry.
What you are doing with the set command at the command line is setting a CLASSPATH for that particular command window. Which is a much better way to handle CLASSPATHs. You might do well to try . instead of %CLASSPATH% as its last entry, if there is no environment variable.


Thank you for the advice.
So, what I did in command line with set command did not change environment variable?

What should I do when I only want to set a claapath for one particular project?
 
Campbell Ritchie
Sheriff
Pie
Posts: 48964
60
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To set the classpath for a particular project, do exactly what you did earlier. As I said, far better than using an environment variable. As far as I know, that sets the classpath for that particular command window, not the environment, but I might be mistaken.
If you want it for an application wrapped in a jar file, that is different. Look in the Java Tutorials under deployment; you will probably find this section most useful for this particular question.
 
Cameron ax
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:To set the classpath for a particular project, do exactly what you did earlier. As I said, far better than using an environment variable. As far as I know, that sets the classpath for that particular command window, not the environment, but I might be mistaken.
If you want it for an application wrapped in a jar file, that is different. Look in the Java Tutorials under deployment; you will probably find this section most useful for this particular question.

Thank you so much.
That is what I have been looking for.

I think what I did earlier did change environment variable. I run that command once, after that, I find I can load htmparser.jar from everywhere.
 
Cameron ax
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:Welcome to the Ranch.

TextPad is just a text editor. As far as I know, it doesn't know anything about Java by itself. So, there's no way to import Java code in any way.

When you compile your code that uses the HTML parser library, you must specify that you're using the library by using the -classpath (or -cp) option on the command line. So, the command to compile your source code would become something like:

C:\MyProject> javac -cp C:\SomeDir\HtmlParser.jar com\mypackage\MyProgram.java

And to run it, you'd specify:

C:\MyProject> java -cp C:\SomeDir\HtmlParser.jar;. com.mypackage.MyProgram

Note: The ";." in the second command is to include the current directory "." into the classpath, because that's where Java is going to look for your own class com.mypackage.MyProgram.


Sorry to bother you once again.

Say I have unziped my htmlparser files on C:\lib, and I placed my program file on C:\myProgram,

So in DOS window, I run this command

javac -cp C:\lib\htmlparser.jar C:\myProgram\myProgram.java

it completed successfully

then I run java myProgram

It gave me NoClassDefFounndError.

But when I use set classpath method

It does work very well.

Why is that?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic