0

I'm having problems compiling my servlet. I have searched around a lot, but none show how to compile with both jars AND class dependencies, just either or.

I have two jars: SQLite and Servlet. However I have managed to compile SQLServer with the SQLite jar.

So my problem is to compile RegisterServlet, which is dependent on both servlet-api.jar and the compiled SQLServer.class.

If anything is unclear, please comment.

What I'm after is something like this:

javac -cp servlet.jar; SQLite.class RegisterServlet.java

enter image description here

Alexey Malev
  • 6,408
  • 4
  • 34
  • 52
Jakkra
  • 641
  • 8
  • 25

1 Answers1

0

I suggest you to try universal solution for building Java applications - Apache Maven. This tool handles the following for you:

  • Managing the dependencies and downloading neccesary jars. For your case, this is going to be servlet-api and sqlite-jdbc.
  • Handling classpath for you - for 95% cases you won't need to worry about it anymore;
  • Compiling your application;
  • Packaging it to whatever form you need - jar, war, ear or something exotical by custom plugins.
Alexey Malev
  • 6,408
  • 4
  • 34
  • 52
  • Thank you, yes I know, I'm going to learn it. But the thing is I just want to get my server running tonight, without having to learn ant/maven/* – Jakkra May 10 '14 at 23:53
  • @Jakkra Then I think you need to compile `RegisterServlet` adding both `servlet-api.jar` and `SqlServer.class` to the classpath as commented under the question. – Alexey Malev May 11 '14 at 00:00
  • Ant is quite easy to learn, and your chances are much higher to get your server running tonight if you copy/paste the compile examples from their docs. – leonm May 11 '14 at 00:00
  • @ Alexey Yah, the thing is I can't figure out how to do that ;) – Jakkra May 11 '14 at 00:01
  • @Jakkra http://stackoverflow.com/questions/9053146/set-folder-for-classpath-in-java - try this. I think the way described there handles both jars and .class-es. – Alexey Malev May 11 '14 at 00:04
  • Can't get it to work. When I try to do like them, I still get error. – Jakkra May 11 '14 at 00:34
  • @Jakkra Consider adding the catalog tree structure with information on where each of the discussed files located. – Alexey Malev May 11 '14 at 00:35
  • Well, to make it easier to compile I just put all files in the same folder. – Jakkra May 11 '14 at 00:40
  • @Jakkra I assume your packages are correct, then you should use `javac -cp . RegisterServlet.java` – Alexey Malev May 11 '14 at 00:42
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/52448/discussion-between-jakkra-and-alexey-malev) – Jakkra May 11 '14 at 00:48