PC_MAGAS Δημοσ. 7 Φεβρουαρίου 2015 Δημοσ. 7 Φεβρουαρίου 2015 Καλησπέρα θέλω να δοκιμάζω το Spring Framework έτσι Δοκίμασα αυτά που λέει στο http://projects.spring.io/spring-framework/ Με την Χρήση του Maven. Το test Project έχει: . ├── pom.xml └── src ├── main │ └── java │ └── test │ ├── Application.java │ ├── MessagePrinter.java │ └── MessageService.java └── test └── java └── test └── AppTest.java 7 directories, 5 files To Pom.xml έχει: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>test</groupId> <artifactId>spring-test</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>spring-test</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project> Το Application.java που έχει: package test; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.*; @Configuration @ComponentScan public class Application { @Bean MessageService mockMessageService() { return new MessageService() { public String getMessage() { return "Hello World!"; } }; } public static void main(String[] args) { ApplicationContext context = new AnnotationConfigApplicationContext(Application.class); MessagePrinter printer = context.getBean(MessagePrinter.class); printer.printMessage(); } } Το MessagePrinter.java που έχει: package test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component public class MessagePrinter { final private MessageService service; @Autowired public MessagePrinter(MessageService service) { this.service = service; } public void printMessage() { System.out.println(this.service.getMessage()); } } Και το MessageService.java που έχει: package test; public interface MessageService { String getMessage(); } Όταν έκτελώ mvn install -e από το terminal παίρνω: pcmagas@dimitris:~/Kwdikas/java/spring-test$ mvn install -e [INFO] Error stacktraces are turned on. [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building spring-test 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-resources-plugin:2.3:resources (default-resources) @ spring-test --- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory /home/pcmagas/Kwdikas/java/spring-test/src/main/resources [INFO] [INFO] --- maven-compiler-plugin:2.0.2:compile (default-compile) @ spring-test --- [INFO] Compiling 3 source files to /home/pcmagas/Kwdikas/java/spring-test/target/classes [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.848s [INFO] Finished at: Sat Feb 07 20:57:18 EET 2015 [INFO] Final Memory: 9M/107M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project spring-test: Compilation failure: Compilation failure: [ERROR] /home/pcmagas/Kwdikas/java/spring-test/src/main/java/test/Application.java:[6,1] error: annotations are not supported in -source 1.3 [ERROR] [ERROR] (use -source 5 or higher to enable annotations) [ERROR] /home/pcmagas/Kwdikas/java/spring-test/src/main/java/test/MessagePrinter.java:[6,1] error: annotations are not supported in -source 1.3 [ERROR] -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project spring-test: Compilation failure at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59) at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196) at org.apache.maven.cli.MavenCli.main(MavenCli.java:141) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356) Caused by: org.apache.maven.plugin.CompilationFailureException: Compilation failure at org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:516) at org.apache.maven.plugin.CompilerMojo.execute(CompilerMojo.java:114) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209) ... 19 more [ERROR] [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException Και ομοίως στο mvn build : pcmagas@dimitris:~/Kwdikas/java/spring-test$ mvn build [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building spring-test 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.212s [INFO] Finished at: Sat Feb 07 20:57:26 EET 2015 [INFO] Final Memory: 5M/107M [INFO] ------------------------------------------------------------------------ [ERROR] Unknown lifecycle phase "build". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-site, site, post-site, site-deploy, pre-clean, clean, post-clean. -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/LifecyclePhaseNotFoundException Μπορεί κάποιος να με βοηθήσει;
t(o.ot) Δημοσ. 7 Φεβρουαρίου 2015 Δημοσ. 7 Φεβρουαρίου 2015 Στο λέει καθαρά: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project spring-test: Compilation failure: Compilation failure: [ERROR] /home/pcmagas/Kwdikas/java/spring-test/src/main/java/test/Application.java:[6,1] error: annotations are not supported in -source 1.3 [ERROR] [ERROR] (use -source 5 or higher to enable annotations) Δοκίμασες να τρέξεις αυτό; $ mvn install -e -source 5
PC_MAGAS Δημοσ. 8 Φεβρουαρίου 2015 Μέλος Δημοσ. 8 Φεβρουαρίου 2015 Το δοκίμασα και παίρνω: pcmagas@dimitris:~/Kwdikas/java/spring-test$ mvn install -e -source 5 [INFO] Error stacktraces are turned on. [ERROR] Error executing Maven. java.io.FileNotFoundException: The specified user settings file does not exist: /home/pcmagas/Kwdikas/java/spring-test/ource at org.apache.maven.cli.MavenCli.settings(MavenCli.java:681) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:193) at org.apache.maven.cli.MavenCli.main(MavenCli.java:141) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
albNik Δημοσ. 9 Φεβρουαρίου 2015 Δημοσ. 9 Φεβρουαρίου 2015 Τι π@π@ρια ειναι αυτο το maven! Αναγκαστηκα στη δουλεια να φτιαξω κατι σε eclipse παραλιγο να παραιτηθώ.
t(o.ot) Δημοσ. 9 Φεβρουαρίου 2015 Δημοσ. 9 Φεβρουαρίου 2015 Η Java, και κατ'επέκταση εργαλεία σαν το maven, δεν είναι η κύρια γλώσσα που χρησιμοποιώ οπότε δεν είμαι ο πλέον κατάλληλος να την κρίνω, αλλά γενικά το configuration της πάντα μου φαινόταν αχανές. Πάντως το βρίσκω λογικό, αν σκεφτεί κανείς την έκτασή της και τις πλατφόρμες τις οποίες υποστηρίζει.
PC_MAGAS Δημοσ. 11 Φεβρουαρίου 2015 Μέλος Δημοσ. 11 Φεβρουαρίου 2015 Ok Κατάφερα να το κάνω compile αλλά πως στο καλό τρέχω το .jar Το pom.xml είναι έτσι: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>test</groupId> <artifactId>spring-test</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>spring-test</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>4.1.4.RELEASE</version> </dependency> </dependencies> <build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <mainClass>test.Application</mainClass> </manifest> </archive> </configuration> </plugin> </plugins> </build> </project> Και το τρέχω έτσι: pcmagas@dimitris:~/Kwdikas/java/spring-test$ java -jar ./target/spring-test-1.0-SNAPSHOT.jar Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2615) at java.lang.Class.getMethod0(Class.java:2856) at java.lang.Class.getMethod(Class.java:1668) at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494) at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486) Caused by: java.lang.ClassNotFoundException: org.springframework.context.ApplicationContext at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) ... 6 more Μήπως θέλει τον tomcat? Δεν έχω πειράξει κάτι στον κώδικα.
t(o.ot) Δημοσ. 11 Φεβρουαρίου 2015 Δημοσ. 11 Φεβρουαρίου 2015 Έχεις βάλει το path για το spring context στο classpath; Σύμφωνα με αυτό, πρέπει να βάλεις το παρακάτω στο configuration του maven: <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>4.1.4.RELEASE</version> </dependency> </dependencies> EDIT: Άκυρο, τώρα είδα ότι το έχεις κάνει. Θα πρέπει να αναλάβει κάποιος πιο έμπειρος από μένα. 2ο EDIT: Αυτό ίσως σε βοηθήσει. tl;dr, τρέξε java -cp '/path/to/jar/file' πριν τρέξεις το πρόγραμμά σου για να πεις στην java πού να κοιτάει για dependencies Γιατί δεν χρησιμοποιείς κάποιο IDE (πχ Eclipse) που θα σε βοηθήσει στο configuration;
PC_MAGAS Δημοσ. 11 Φεβρουαρίου 2015 Μέλος Δημοσ. 11 Φεβρουαρίου 2015 Λέω να χρησιμοποιήσω το InteliJ αν και δεν με βολεύει για Java κάποιο Ide για Php χρησιμοποιώ το Aptana Studio. Αλλά το IDE έχει Abstractions που καλό είναι να ξέρεις τι παίζει από πίσω έτσι σε IDE θα παίζεις Καλύτερα Μπάλα. Btw που θα βρώ το Spring Jar?
Προτεινόμενες αναρτήσεις
Δημιουργήστε ένα λογαριασμό ή συνδεθείτε για να σχολιάσετε
Πρέπει να είστε μέλος για να αφήσετε σχόλιο
Δημιουργία λογαριασμού
Εγγραφείτε με νέο λογαριασμό στην κοινότητα μας. Είναι πανεύκολο!
Δημιουργία νέου λογαριασμούΣύνδεση
Έχετε ήδη λογαριασμό; Συνδεθείτε εδώ.
Συνδεθείτε τώρα