I'm working on a groovy project that runs as java application in Eclipse.
Normally there are normal class files under the groovy files, but when I make a clean install of the project with maven, it deletes those java classes, so i can't run it in eclipse anymore.
Why is that so? I have another project that has the same structure without this problem.
Greetings
edit:
I made a screenshot to clear what I mean.
The PDFConverter is how I want/know it the other is what I get and can't run in Eclipse anymore
I would look at your_project/target/classes/ directory, that's where Maven puts .class files.
Although it's not entirely clear what are you asking about.
Related
I've made a project in Java using Eclipse using the jnetpcap library which needs WinPCap to be installed to work properly. However, there's no winpcap library included in my project only jnetpcap. But when i extract the project into a generated jar with libraries, or with the libraries in a different folder, it somehow doesn't work. Why does everything work when i run the program from eclipse, but not as an extracted project?
Thanks in advance.
I faced the same issue few years back. Jnetpcap for eclipse comes with winpcap. You need to export your project on eclipse as runnable jar. There you have an option to select which says extract required libraries in the generated jar. In this way, the all the dependent libraries will be included in the exported runnable jar file.
The links below are some of the helpful links:
Create runnable jar in eclipse
Visit the post on winpcap website jnetpcap: a java wrapper for libpcap and winpcap
Does this thread helps you out? I would guess that you have not wrapped your dependency into the .jar file but only in eclipse. That is why it works inside your IDE.
You didn't declare your main class for the jar file.
Right click on your solution in eclipse->Run as-> Run configuration -> Main class -> choose you main class.
Now build your jar from the beginning and try to execute it.
I've imported a small example Java program to mess around with, and when I run it using IntelliJ IDEA it creates a clone of the /src/ folder in /out/production/src/
What is the reasoning behind this? Have I imported my source code incorrectly or am I using an incorrect Project Structure?
The application runs exactly how I expect it to, but the file structure for /out/production/ is all-in-red in IntelliJ IDEA.
It's the compiled .class files.
I obviously don't use Java or IntelliJ IDEA often enough.
I have a 202 instructor who says that he feels its fine to use netbeans or eclipse but that for the final project he wants a file that he can load on his xp (I'm not sure why xp) machine, compile and run with the following commands:
javac *.java
java FinalProject
Up to this point I have been editing in a simple text pad like program and missing netbeans but to be fair I can't figure out how to code in netbeans in such a way that I get a generic set of files with no handily added code. If anyone could tell me how to convince netbeans that I don't need packages, ant build, team work software, and a bunch of netbeans helpful files lying around in my code I would really really appreciate it.
First you must get better understanding about IDE. Refer here
for NetBeans and Eclipse
When we write a simple program in few lines we can do with notepad and compile with javac. If we go for a big project there are lot of stuff and features required like
Adding external lib
UI Frame work
Identifying syntax error
Easy compilation, debugging and execution
Writing unit test etc.,
In netbeans, you just take "src" folder and use it.
So with netbeans all the source code files get put into a src directory. This contains nothing other than source files. In order to compile it using javac *.java you should place all your java files in the <default package> or without a package(Netbeans will warn that this is bad practice but you can ignore that for now). To run the program using java FinalProject you need to make a java file called FinalProject.java(with a class called FinalProject. You can create any additional classes in external files as long as they all go in the same <default package>.
Netbeans' scripts will just make it easier for you to compile and test your code. And to submit you just need to submit all the files in the src folder.
Also, as a side note, If you are creating GUI's using netbeans, you should probably use GridBagLayout rather than the default layout as that adds an additional library that will mean that your instructor's compilation will fail.
first of all sorry for my bad english. I have a question and I cant find an answer anywhere.
My Programm exports some loose *.java files withouth any entrypoint. The written API allows an CMD to be executed. Problem is, the CMD Order to start eclipse with parameters. My questions is is it possible to start eclipse 3.3-3.6 with a command line parameter to create a project. Creating a Workspace through -data c:\xxxx\myworkspace is no problem but since eclipse sees no files outside a project, i need to make one so i can put my java files into it and startup an remote debug after it. The Plan is to startup an external export java file, which starts eclipse with the defined workspace and a fresh project (with the exported java files) for usage.
Using Maven it's possible to create an Eclipse project and all kinds of useful stuff, http://maven.apache.org/guides/mini/guide-ide-eclipse.html gives at least a starting point
There are some tools like Maven or Ant plugins that create Eclipse projects from some structural information (e.g. the Maven plugin reads the pom.xml).
If your code is unstructured it might be hard to create a fully functional Eclipse project. You might be able to create a Java project and define its source path (in fact it's a simple XML file called .project - you could easily write one yourself) but any other information like additional dependencies etc. would have to be added manually.
Besides that, creating a simple project from existing sources isn't that hard in Eclipse. Why don't you just do it manually?
I am new to Java (and Eclipse) but I have used .NET (and Visual Studio) a fair amount. I also know about compiling C/C++ code and things like that. I know that at the end I get either an EXE or a nice binary file that can be run from the command line.
I have been making a Java utility that uses some external libraries. I need to compile this into an executable that I can run from the command line on a unix machine, but I cannot find any way to do this.
I can build and run/debug in Eclipse, but that is no use to me as this code will be run on a webserver. I just need all the dependancies compiled in to one file but after hours of searching on Google, the best thing I could find was the Fat-JAR plugin for Eclipse and after using that I just get the following error when I try to run the file:
Exception in thread "main" java.lang.NoClassDefFoundError: Network/jar
This is really confusing me and as it is such an essential thing to be able to do I am sure I must be missing something blindingly obvious, but as I said, after hours of searching I have gotten nowhere.
I really appreciate any help you can give me. Thanks.
If you build your java app using Maven (which can be done with every major IDE), then you can use the maven Shade Plugin to build a shaded jar file; this is a jar file with all of its dependencies included.
A shaded jar can be run from the command line like this:
java -jar myjar.jar command line options
You're doing something standard and you're using eclipse. This means, in your case, Maven is your friend. Download and install the M2Eclipse plug-in. Maven is best at managing dependencies. So, creating a jar with dependencies included will be very, very straight forward. There are thousands of examples on the web and in StackOverflow. If you have problems setting it up, comment on this and I can point you in the right direction.
Sounds like your class path on the server needs to be modified to pick up the jar file containing the Network class. How are you executing your program? What path(s) are you putting in the -cp option?
If you are not sure how to find out the contents inside a jar file, run jar tf , this will list the packaged classes. Validate that one of the jars in your CLASSPATH has that class it says missing.
Give us more details and we can help solve it.
I think I should first explain some basics. A Java class can be run as an application if it has a public static void main(String[] args) method. If it has this method, you can run it from command line as:
java my.package.MyClass <attributes>
Before launching your app, you need to make sure that all required .jar files (and the root of your own class folders, if you did not make a jar from your classes) are in the CLASSPATH environment variable.
These are the absolute basics. When you are building a more complex app, or an app for distribution, you'll probably use maven or ant or some other tool that makes your life easier.